annotate intermediate.php @ 1241:879b0b20b20c
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 |
|
rev |
line source |
n@1241
|
1 <?php
|
n@1241
|
2 // This script manages the intermediate saves
|
n@1241
|
3
|
n@1241
|
4 //http://stackoverflow.com/questions/4778865/php-simplexml-addchild-with-another-simplexmlelement
|
n@1241
|
5 function sxml_append(SimpleXMLElement $to, SimpleXMLElement $from) {
|
n@1241
|
6 $toDom = dom_import_simplexml($to);
|
n@1241
|
7 $fromDom = dom_import_simplexml($from);
|
n@1241
|
8 $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
|
n@1241
|
9 }
|
n@1241
|
10
|
n@1241
|
11 $file_key = $_GET['key'];
|
n@1241
|
12 $nodeName = $_GET['node'];
|
n@1241
|
13 $id = $_GET['id'];
|
n@1241
|
14 $filename = "saves/save-".$file_key.".xml";
|
n@1241
|
15 $save_ok = '<response state="OK"><message>OK</message><file>'.$filename.'</file></response>';
|
n@1241
|
16 $save_error = '<response state="error"><message>Could not update the file</message><file>'.$filename.'</file></response>';
|
n@1241
|
17 $node = file_get_contents('php://input');
|
n@1241
|
18 $inject_xml = simplexml_load_string($node);
|
n@1241
|
19 $xml_string = file_get_contents($filename, FILE_TEXT);
|
n@1241
|
20 $xml_object = simplexml_load_string($xml_string);
|
n@1241
|
21
|
n@1241
|
22 if ($nodeName == "waetresult") {
|
n@1241
|
23 sxml_append($xml_object, $inject_xml);
|
n@1241
|
24 } else {
|
n@1241
|
25 if ($id == "undefined") {
|
n@1241
|
26 return;
|
n@1241
|
27 } else {
|
n@1241
|
28 $result = $xml_object->xpath("".$nodeName."[@id='".$id."']");
|
n@1241
|
29 sxml_append($result[0], $inject_xml);
|
n@1241
|
30 }
|
n@1241
|
31 }
|
n@1241
|
32 $xml_object->asXML($filename)
|
n@1241
|
33 ?> |