# HG changeset patch # User Nicholas Jillings # Date 1457521926 0 # Node ID 4c616e2ef71a8fcc4bb8f501f41564e7571a7446 # Parent 584efb7ec6b39125c86de1108f04f066bcaa3cbb 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). diff -r 584efb7ec6b3 -r 4c616e2ef71a core.js --- a/core.js Tue Mar 08 18:12:14 2016 +0000 +++ b/core.js Wed Mar 09 11:12:06 2016 +0000 @@ -213,20 +213,20 @@ } return; } - + // Build the specification + specification.decode(projectXML); // Generate the session-key storage.initialise(); } else if (responseDocument.children[0].nodeName == "waetresult") { // document is a result projectXML = responseDocument.getElementsByTagName('waet')[0]; + // Build the specification + specification.decode(projectXML); // Use the session-key var sessionKey = responseDocument.children[0].getAttribute(key); storage.initialise(sessionKey); } - - // Build the specification - specification.decode(projectXML); /// CHECK FOR SAMPLE RATE COMPATIBILITY if (specification.sampleRate != undefined) { if (Number(specification.sampleRate) != audioContext.sampleRate) { @@ -744,6 +744,7 @@ { this.store.postResult(node); } + this.store.finish(); advanceState(); } }; @@ -822,6 +823,7 @@ { if (specification.testPages <= i && specification.testPages != 0) {break;} this.stateMap.push(pageHolder[i]); + storage.createTestPageStore(pageHolder[i]); } if (specification.preTest != null) {this.preTestSurvey = specification.preTest;} @@ -872,7 +874,7 @@ { this.currentStateMap.audioElements = randomiseOrder(this.currentStateMap.audioElements); } - this.currentStore = storage.createTestPageStore(this.currentStateMap); + this.currentStore = storage.testPages[this.stateIndex]; if (this.currentStateMap.preTest != null) { this.currentStatePosition = 'pre'; @@ -903,6 +905,7 @@ case 'post': this.stateIndex++; this.currentStateMap = null; + this.currentStore.finish(); this.advanceState(); break; }; @@ -3144,6 +3147,22 @@ this.request.open("GET","keygen.php?key="+temp_key,true); this.request.addEventListener("load",this); this.request.send(); + }, + postData: function(nodeName,id,xml) { + // nodeName: the node name to find + // id: the id of the node (null if location==root) + // xml: the XML node to append + if (this.key != null) { + var postXML = new XMLHttpRequest; + postXML.open("POST","intermediate.php?key="+this.key+"&node="+nodeName+"&id="+id); + postXML.setRequestHeader('Content-Type','text/xml'); + postXML.onerror = function() { + console.log("Error posting: "+this.responseText); + } + var parent = document.createElement("div"); + parent.appendChild(xml); + postXML.send([parent.innerHTML]); + } } } @@ -3203,6 +3222,12 @@ break; } }; + + this.finish = function() { + if (this.parent.document != undefined) { + this.parent.SessionKey.postData("waetresult",null,this.XMLDOM); + } + }; }; this.pageNode = function(parent,specification) @@ -3241,6 +3266,10 @@ } this.parent.root.appendChild(this.XMLDOM); + + this.finish = function() { + this.parent.SessionKey.postData("waetresult",null,this.XMLDOM); + } }; this.finish = function() { diff -r 584efb7ec6b3 -r 4c616e2ef71a intermediate.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intermediate.php Wed Mar 09 11:12:06 2016 +0000 @@ -0,0 +1,33 @@ +appendChild($toDom->ownerDocument->importNode($fromDom, true)); +} + +$file_key = $_GET['key']; +$nodeName = $_GET['node']; +$id = $_GET['id']; +$filename = "saves/save-".$file_key.".xml"; +$save_ok = 'OK'.$filename.''; +$save_error = 'Could not update the file'.$filename.''; +$node = file_get_contents('php://input'); +$inject_xml = simplexml_load_string($node); +$xml_string = file_get_contents($filename, FILE_TEXT); +$xml_object = simplexml_load_string($xml_string); + +if ($nodeName == "waetresult") { + sxml_append($xml_object, $inject_xml); +} else { + if ($id == "undefined") { + return; + } else { + $result = $xml_object->xpath("".$nodeName."[@id='".$id."']"); + sxml_append($result[0], $inject_xml); + } +} +$xml_object->asXML($filename) +?> \ No newline at end of file diff -r 584efb7ec6b3 -r 4c616e2ef71a keygen.php --- a/keygen.php Tue Mar 08 18:12:14 2016 +0000 +++ b/keygen.php Wed Mar 09 11:12:06 2016 +0000 @@ -1,7 +1,7 @@ '); + $doc_struct->addAttribute("key",$key_requested); // Add start time // Add IP Address information + // Save the file + $doc_struct->asXML("saves/save-".$key_requested.".xml"); return; } else { echo $xml_error;