Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <title>Test Johnny</title>
- <head>
- <meta charset="utf-8"/>
- <script type="text/javascript">
- function swap(){
- }
- </script>
- </head>
- <body>
- <?php
- if($_POST['action'] == 'Save' or $_POST['action'] == 'Swap'){
- $pName1 = $_POST['pName1'];
- $pScore1 = $_POST['pScore1'];
- $pCountry1 = $_POST['pCountry1'];
- $pName2 = $_POST['pName2'];
- $pScore2 = $_POST['pScore2'];
- $pCountry2 = $_POST['pCountry2'];
- $timestamp = time();
- if($_POST['action'] == 'Swap'){
- $array = array(
- "timestamp" => $timestamp,
- "pName1" => $pName2,
- "pScore1" => $pScore2,
- "pCountry1" => $pCountry2,
- "pName2" => $pName1,
- "pScore2" => $pScore1,
- "pCountry2" => $pCountry1
- );
- echo "Swap ";
- }
- if($_POST['action'] == 'Save'){
- $array = array(
- "timestamp" => $timestamp,
- "pName1" => $pName1,
- "pScore1" => $pScore1,
- "pCountry1" => $pCountry1,
- "pName2" => $pName2,
- "pScore2" => $pScore2,
- "pCountry2" => $pCountry2
- );
- echo "Save ";
- }
- function arrayToXml($array, $rootElement = null, $xml = null) {
- $_xml = $xml;
- if ($_xml === null) {
- $_xml = new SimpleXMLElement($rootElement !== null ? $rootElement : '<items/>');
- }
- foreach ($array as $k => $v) {
- if (is_array($v)) {
- arrayToXml($v, $k, $_xml->addChild($k));
- } else {
- $_xml->addChild($k, $v);
- }
- }
- return $_xml->asXML();
- }
- $xmlarray = arrayToXml($array);
- $mytext = $xmlarray;
- $fp = fopen("streamcontrol.xml", "w+");
- $test = fwrite($fp, $mytext);
- if ($test){
- echo "Данные успешно обновлены";
- ?>
- <form action="" method="POST">
- <table>
- <tr>
- <td>Игрок</td><td>Счет</td><td>Регион</td>
- </tr>
- <tr>
- <td><input type="text" name="pName1" id="pName1" value="<? echo $pName1; ?>"/></td>
- <td><input type="number" name="pScore1" id="pScore1" value="<? echo $pScore1; ?>"/></td>
- <td><input type="text" name="pCountry1" id="pCountry1" value="<? echo $pCountry1; ?>"/></td>
- </tr>
- <tr>
- <td><input type="text" name="pName2" id="pName2" value="<? echo $pName2; ?>"/></td>
- <td><input type="number" name="pScore2" id="pScore2" value="<? echo $pScore2; ?>"/></td>
- <td><input type="text" name="pCountry2" id="pCountry2" value="<? echo $pCountry2; ?>"/></td>
- </tr>
- </table>
- <br />
- <input type="submit" name="action" value="Save"/>
- <input type="submit" name="action" value="Swap"/>
- </form>
- <?;
- }else{
- echo 'Ошибка при записи в файл.';
- }
- fclose($fp);
- header("Refresh:0");
- }
- else{
- $xmlstring = file_get_contents('streamcontrol.xml', true);
- $xml = simplexml_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
- $json = json_encode($xml);
- $xmldata = json_decode($json,TRUE);
- ?>
- <form action="" method="POST">
- <table>
- <tr>
- <td>Игрок</td><td>Счет</td><td>Регион</td>
- </tr>
- <tr>
- <td><input type="text" name="pName1" id="pName1" value="<? echo $xmldata['pName1']; ?>"/></td>
- <td><input type="number" name="pScore1" id="pScore1" value="<? echo $xmldata['pScore1']; ?>"/></td>
- <td><input type="text" name="pCountry1" id="pCountry1" value="<? echo $xmldata['pCountry1']; ?>"/></td>
- </tr>
- <tr>
- <td><input type="text" name="pName2" id="pName2" value="<? echo $xmldata['pName2']; ?>"/></td>
- <td><input type="number" name="pScore2" id="pScore2" value="<? echo $xmldata['pScore2']; ?>"/></td>
- <td><input type="text" name="pCountry2" id="pCountry2" value="<? echo $xmldata['pCountry2']; ?>"/></td>
- </tr>
- </table>
- <br />
- <input type="submit" name="action" value="Save"/>
- <input type="submit" name="action" value="Swap"/>
- </form>
- <?}?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement