comparison intermediate.php @ 587:0d6d7618f6da Dev_main

WIP. Adding intermediate save options. Will require mass editing of save engine as it stands, so still WIP (note: this version will not work on python server).
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 09 Mar 2016 11:12:06 +0000
parents
children
comparison
equal deleted inserted replaced
586:b13558e54de8 587:0d6d7618f6da
1 <?php
2 // This script manages the intermediate saves
3
4 //http://stackoverflow.com/questions/4778865/php-simplexml-addchild-with-another-simplexmlelement
5 function sxml_append(SimpleXMLElement $to, SimpleXMLElement $from) {
6 $toDom = dom_import_simplexml($to);
7 $fromDom = dom_import_simplexml($from);
8 $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
9 }
10
11 $file_key = $_GET['key'];
12 $nodeName = $_GET['node'];
13 $id = $_GET['id'];
14 $filename = "saves/save-".$file_key.".xml";
15 $save_ok = '<response state="OK"><message>OK</message><file>'.$filename.'</file></response>';
16 $save_error = '<response state="error"><message>Could not update the file</message><file>'.$filename.'</file></response>';
17 $node = file_get_contents('php://input');
18 $inject_xml = simplexml_load_string($node);
19 $xml_string = file_get_contents($filename, FILE_TEXT);
20 $xml_object = simplexml_load_string($xml_string);
21
22 if ($nodeName == "waetresult") {
23 sxml_append($xml_object, $inject_xml);
24 } else {
25 if ($id == "undefined") {
26 return;
27 } else {
28 $result = $xml_object->xpath("".$nodeName."[@id='".$id."']");
29 sxml_append($result[0], $inject_xml);
30 }
31 }
32 $xml_object->asXML($filename)
33 ?>