function setRoomsXml($xmldata)
{
- //TODO:implement
+ //TODO:do more extensive syntax checking and better error reporting
+ //get XML
+ $xml=new DOMDocument;
+ if($xml->loadXML($xmldata)===false){
+ header("X-MagicSmoke-Status: SyntaxError");
+ echo "Unable to parse XML.";
+ return;
+ }
+ //stage 2: extract data from XML
+ $doc=$xml->documentElement;
+ global $db;
+ foreach($doc->getElementsByTagName("Room") as $room){
+ //get data
+ $cap=$room->getAttribute("capacity")+0;
+ $id=false;
+ $descr=false;
+ foreach($room->getElementsByTagName("ID") as $el)
+ foreach($el->childNodes as $cn)
+ if($cn->nodeType==XML_TEXT_NODE)
+ $id=trim($cn->wholeText);
+ foreach($room->getElementsByTagName("Description") as $el)
+ foreach($el->childNodes as $cn)
+ if($cn->nodeType==XML_TEXT_NODE)
+ $descr=trim($cn->wholeText);
+ if($id===false)continue;
+ $db->beginTransaction();
+ $res=$db->select("room","roomid","roomid=".$db->escapeString($id));
+ if(count($res)>0){
+ $db->update("room",array("capacity"=>$cap,"description"=>$descr),"roomid=".$db->escapeString($id));
+ }else{
+ $db->insert("room",array("roomid"=>$id,"capacity"=>$cap,"description"=>$descr));
+ }
+ $db->commitTransaction();
+ }
+ header("X-MagicSmoke-Status: Ok");
}
?>
\ No newline at end of file