set_backend.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. <div class="envor-content">
  17. <!--
  18. Page Title start
  19. //-->
  20. <section class="envor-page-title-1" data-stellar-background-ratio="0.5">
  21. <div class="container">
  22. <div class="row">
  23. <div class="col-lg-9 col-md-9 col-sm-9">
  24. <h1><?php echo $lang->showWord("backend"); ?></h1>
  25. </div>
  26. </div>
  27. </div>
  28. <!--
  29. Page Title end
  30. //-->
  31. </section>
  32. <!--
  33. Main Content start
  34. //-->
  35. <section class="envor-section">
  36. <div class="container">
  37. <div class="row">
  38. <div class="col-lg-12">
  39. <div class="envor-sorting" id="faq-sorting">
  40. <div class="envor-toggle">
  41. <!--Common Information-->
  42. <article class="envor-sorting-item css">
  43. <header><?php echo $lang->showWord("common_information"); ?><i class="fa fa-plus"></i></header>
  44. <section>
  45. <div class="form-group" style="display:<?php echo $am101;?>">
  46. <label>BackendConnTimeout</label>
  47. <input type="text" name="BackendConnTimeout" id="BackendConnTimeout" class="form-control" value="<?php echo $obj->{'BackendConnTimeout'};?>">
  48. <small class="form-text text-muted-red">seconds</small>
  49. </div>
  50. <div class="form-group" style="display:<?php echo $am101;?>">
  51. <label>OfflinePolicy</label>
  52. <select class="form-control" id="OfflinePolicy" name="OfflinePolicy">
  53. <option value="0" <?php echo ord($obj->{'OfflinePolicy'})=="0"?"selected":""?>>local list</option>
  54. <option value="1" <?php echo ord($obj->{'OfflinePolicy'})=="1"?"selected":""?>>Phihong RFID tag</option>
  55. <option value="2" <?php echo ord($obj->{'OfflinePolicy'})=="2"?"selected":""?>>free charging</option>
  56. <option value="3" <?php echo ord($obj->{'OfflinePolicy'})=="3"?"selected":""?>>no charging</option>
  57. </select>
  58. </div>
  59. <div class="form-group" style="display:<?php echo $am101;?>">
  60. <label>OfflineMaxChargeEnergy</label>
  61. <small class="form-text text-muted-red">kWh</small>
  62. <input type="text" name="OfflineMaxChargeEnergy" id="OfflineMaxChargeEnergy" class="form-control" value="<?php echo $obj->{'OfflineMaxChargeEnergy'};?>">
  63. </div>
  64. <div class="form-group" style="display:<?php echo $am101;?>">
  65. <label>OfflineMaxChargeDuration</label>
  66. <small class="form-text text-muted-red">minutes</small>
  67. <input type="text" name="OfflineMaxChargeDuration" id="OfflineMaxChargeDuration" class="form-control" value="<?php echo $obj->{'OfflineMaxChargeDuration'};?>">
  68. </div>
  69. </section>
  70. </article>
  71. <!--OCPP Backend-->
  72. <article class="envor-sorting-item css">
  73. <header><?php echo $lang->showWord("OCPP_backend"); ?><i class="fa fa-plus"></i></header>
  74. <section>
  75. <div class="form-group" style="display:<?php echo $am101;?>">
  76. <label>OcppConnStatus</label>
  77. <input type="text" readonly class="form-control" placeholder="<?php echo $OcppConnStatus;?>">
  78. <input type="hidden" name="OcppConnStatus" id="OcppConnStatus" value="<?php echo ord($obj->{'OcppConnStatus'});?>">
  79. </div>
  80. <div class="form-group" style="display:<?php echo $am101;?>">
  81. <label>OcppServerURL</label>
  82. <input type="text" name="OcppServerURL" id="OcppServerURL" class="form-control" value="<?php echo $obj->{'OcppServerURL'};?>">
  83. </div>
  84. <div class="form-group" style="display:<?php echo $am101;?>">
  85. <label>ChargeBoxId</label>
  86. <input type="text" name="ChargeBoxId" id="ChargeBoxId" class="form-control" value="<?php echo $obj->{'ChargeBoxId'};?>">
  87. </div>
  88. </section>
  89. </article>
  90. <article class="envor-sorting-item css">
  91. <div align="center"><button id="save"><?php echo $lang->showWord("set")?></button></div>
  92. </article>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </section>
  99. </div>
  100. <?php
  101. include 'foot.php';
  102. ?>
  103. <script type="text/JavaScript">
  104. document.getElementById("save").onclick = function() {
  105. if(formCheck())
  106. {
  107. // 發送 Ajax 查詢請求並處理
  108. var request = new XMLHttpRequest();
  109. request.open("POST", "set_backend_action.php");
  110. // POST 參數須使用 send() 發送
  111. var data = "BackendConnTimeout=" + document.getElementById("BackendConnTimeout").value +
  112. "&OfflinePolicy=" + document.getElementById("OfflinePolicy").value +
  113. "&OfflineMaxChargeEnergy=" + document.getElementById("OfflineMaxChargeEnergy").value+
  114. "&OfflineMaxChargeDuration=" + document.getElementById("OfflineMaxChargeDuration").value+
  115. // "&OcppConnStatus=" + document.getElementById("OcppConnStatus").value+
  116. "&OcppServerURL=" + document.getElementById("OcppServerURL").value+
  117. "&ChargeBoxId=" + document.getElementById("ChargeBoxId").value;
  118. // POST 請求必須設置表頭在 open() 下面,send() 上面
  119. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  120. request.send(data);
  121. request.onreadystatechange = function() {
  122. // 伺服器請求完成
  123. if (request.readyState == 4) {
  124. // 伺服器回應成功
  125. if (request.status == 200) {
  126. alert("<?php echo $lang->showWord("done")?>");
  127. //location.reload();
  128. // getInfo();
  129. } else {
  130. alert("發生錯誤" + request.status);
  131. }
  132. }
  133. }
  134. }
  135. }
  136. function formCheck()
  137. {
  138. var OcppServerURL = document.getElementById("OcppServerURL").value;
  139. 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,}))+/;
  140. if(OcppServerURL.match(tests)==null){
  141. alert("OcppServerURL format error!");
  142. document.getElementById("OcppServerURL").focus();
  143. return false;
  144. }
  145. return true;
  146. }
  147. function isNumberKey(evt)
  148. {
  149. var charCode = (evt.which) ? evt.which : event.keyCode
  150. if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
  151. return false;
  152. return true;
  153. }
  154. </script>
  155. </html>