Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. <html>
  2. <title>Test Johnny</title>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <script type="text/javascript">
  6. function swap(){
  7.  
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <?php
  14. if($_POST['action'] == 'Save' or $_POST['action'] == 'Swap'){
  15.  
  16. $pName1 = $_POST['pName1'];
  17. $pScore1 = $_POST['pScore1'];
  18. $pCountry1 = $_POST['pCountry1'];
  19.  
  20. $pName2 = $_POST['pName2'];
  21. $pScore2 = $_POST['pScore2'];
  22. $pCountry2 = $_POST['pCountry2'];
  23.  
  24. $timestamp = time();
  25.  
  26. if($_POST['action'] == 'Swap'){
  27. $array = array(
  28. "timestamp" => $timestamp,
  29. "pName1" => $pName2,
  30. "pScore1" => $pScore2,
  31. "pCountry1" => $pCountry2,
  32. "pName2" => $pName1,
  33. "pScore2" => $pScore1,
  34. "pCountry2" => $pCountry1
  35. );
  36. echo "Swap ";
  37. }
  38. if($_POST['action'] == 'Save'){
  39. $array = array(
  40. "timestamp" => $timestamp,
  41. "pName1" => $pName1,
  42. "pScore1" => $pScore1,
  43. "pCountry1" => $pCountry1,
  44. "pName2" => $pName2,
  45. "pScore2" => $pScore2,
  46. "pCountry2" => $pCountry2
  47. );
  48. echo "Save ";
  49. }
  50.  
  51.  
  52.  
  53.  
  54. function arrayToXml($array, $rootElement = null, $xml = null) {
  55. $_xml = $xml;
  56.  
  57. if ($_xml === null) {
  58. $_xml = new SimpleXMLElement($rootElement !== null ? $rootElement : '<items/>');
  59. }
  60.  
  61. foreach ($array as $k => $v) {
  62. if (is_array($v)) {
  63. arrayToXml($v, $k, $_xml->addChild($k));
  64. } else {
  65. $_xml->addChild($k, $v);
  66. }
  67. }
  68.  
  69. return $_xml->asXML();
  70. }
  71.  
  72. $xmlarray = arrayToXml($array);
  73.  
  74. $mytext = $xmlarray;
  75.  
  76. $fp = fopen("streamcontrol.xml", "w+");
  77. $test = fwrite($fp, $mytext);
  78. if ($test){
  79. echo "Данные успешно обновлены";
  80.  
  81. ?>
  82.  
  83. <form action="" method="POST">
  84. <table>
  85. <tr>
  86. <td>Игрок</td><td>Счет</td><td>Регион</td>
  87. </tr>
  88. <tr>
  89. <td><input type="text" name="pName1" id="pName1" value="<? echo $pName1; ?>"/></td>
  90. <td><input type="number" name="pScore1" id="pScore1" value="<? echo $pScore1; ?>"/></td>
  91. <td><input type="text" name="pCountry1" id="pCountry1" value="<? echo $pCountry1; ?>"/></td>
  92. </tr>
  93. <tr>
  94. <td><input type="text" name="pName2" id="pName2" value="<? echo $pName2; ?>"/></td>
  95. <td><input type="number" name="pScore2" id="pScore2" value="<? echo $pScore2; ?>"/></td>
  96. <td><input type="text" name="pCountry2" id="pCountry2" value="<? echo $pCountry2; ?>"/></td>
  97. </tr>
  98. </table>
  99. <br />
  100. <input type="submit" name="action" value="Save"/> &nbsp; &nbsp; &nbsp;
  101. <input type="submit" name="action" value="Swap"/>
  102. </form>
  103.  
  104. <?;
  105. }else{
  106. echo 'Ошибка при записи в файл.';
  107. }
  108. fclose($fp);
  109. header("Refresh:0");
  110.  
  111.  
  112.  
  113. }
  114. else{
  115. $xmlstring = file_get_contents('streamcontrol.xml', true);
  116. $xml = simplexml_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
  117. $json = json_encode($xml);
  118. $xmldata = json_decode($json,TRUE);
  119.  
  120. ?>
  121. <form action="" method="POST">
  122. <table>
  123. <tr>
  124. <td>Игрок</td><td>Счет</td><td>Регион</td>
  125. </tr>
  126. <tr>
  127. <td><input type="text" name="pName1" id="pName1" value="<? echo $xmldata['pName1']; ?>"/></td>
  128. <td><input type="number" name="pScore1" id="pScore1" value="<? echo $xmldata['pScore1']; ?>"/></td>
  129. <td><input type="text" name="pCountry1" id="pCountry1" value="<? echo $xmldata['pCountry1']; ?>"/></td>
  130. </tr>
  131. <tr>
  132. <td><input type="text" name="pName2" id="pName2" value="<? echo $xmldata['pName2']; ?>"/></td>
  133. <td><input type="number" name="pScore2" id="pScore2" value="<? echo $xmldata['pScore2']; ?>"/></td>
  134. <td><input type="text" name="pCountry2" id="pCountry2" value="<? echo $xmldata['pCountry2']; ?>"/></td>
  135. </tr>
  136. </table>
  137. <br />
  138. <input type="submit" name="action" value="Save"/> &nbsp; &nbsp; &nbsp;
  139. <input type="submit" name="action" value="Swap"/>
  140. </form>
  141.  
  142. <?}?>
  143.  
  144.  
  145. </body>
  146. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement