de acá obtuve el código
http://philflash.inway.fr/realestatep2/index.html
Código :
<?php /** * RealEstate in Flash with PHP * by PhilFlash - http://philflash.inway.fr */ require_once('connectdb.php'); // For debug // If true, save the XML in the file debugOperation.xml // To test, enter: operation.php?debug=1 => read the file debugOperation.xml $debugXmlOperation = false; // ----- NO CACHE ----- session_cache_limiter('nocache'); // General header for no caching $now = gmdate('D, d M Y H:i:s') . ' GMT'; header('Expires: ' . $now); // rfc2616 - Section 14.21 header('Last-Modified: ' . $now); header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 header('Pragma: no-cache'); // HTTP/1.0 header("Content-Type: text/xml; charset=utf-8"); // ----- Functions ----- function formatString($str) { $str = utf8_decode($str); return "'".mysql_escape_string($str)."'"; } function formatAttributeValue($theValue) { $theValue = utf8_encode($theValue); return $theValue; } function formatAttributeNumberValue($theValue) { if ($theValue == "") { return "_NULL_"; } return $theValue; } function formatTagValue($theValue) { if ($theValue == "") { return "_NULL_"; } $theValue = htmlspecialchars($theValue, ENT_COMPAT); $theValue = str_replace("'", "'", $theValue); $theValue = utf8_encode($theValue); return $theValue; } // ----- MySQL Connection ----- mysql_select_db($database_db, $connect_db); // ----- Read operation in XML ----- $xmlOperation = ""; $domOperation = new DOMDocument(); if (isset($debug) && $debug == "1") { $domOperation->load("debugOperation.xml"); } else { $xmlOperation = file_get_contents("php://input"); if ($xmlOperation == "") { // die("*** WAIT A PARAMS XML FILE ***"); $xmlOperation = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><params></params>"; } $domOperation->loadXML($xmlOperation); if ($debugXmlOperation) { $fp = fopen("debugOperation.xml", "w"); fwrite($fp, $domOperation->saveXML()); fclose($fp); } } // ----- Prepare XML to send ----- $dom = new DOMDocument(); $dom->loadXML("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><roperation></roperation>"); $rcode = 0; // 0:bad operation, 1: ok $rarg = ""; // arg returned $errmsg = ""; // error message $rootNode = $dom->documentElement; // ----- Check operation ----- $nodeOperation = $domOperation->documentElement; $operation = $nodeOperation->getAttribute("opcode"); // -- process "remove" operation -- if ($operation == "remove") { $arg = $nodeOperation->getAttribute("arg"); if ($arg != NULL && $arg != "") { $query = "DELETE FROM listing where `mls_id` = " . formatString($arg); // Exec query $result = mysql_query($query); if ($result) { $num_rows = mysql_affected_rows(); $rcode = 1; } else { $num_rows = 0; } $rarg = $num_rows; } } // -- process "update" operation -- else if ($operation == "update") { $valuesNode = $nodeOperation->getElementsByTagName("values"); $valueNode = $valuesNode->item(0); $updateStmt = ""; $updateCondition = ""; if ($valueNode->hasAttributes()) { $addStmt = ""; foreach ($valueNode->attributes as $attribute) { $name = $attribute->name; $checkName = ";".$name; $value = $attribute->value; if ($name == "mls_id") { $updateCondition = "`" . $name . "` = " . formatString($value); $arg = $value; } else if (strpos(";address;city;state;zipcode;status;stories;type;remarks;listedOn;", $checkName) === false) { // number $updateStmt = $updateStmt . $addStmt . "`" . $name . "` = " . mysql_escape_string($value); $addStmt = ", "; } else { // string $updateStmt = $updateStmt . $addStmt . "`" . $name . "` = " . formatString($value); $addStmt = ", "; } } } $query = "UPDATE listing SET " . $updateStmt . " WHERE " . $updateCondition; // -- Exec query -- $result = mysql_query($query); if ($result) { $num_rows = mysql_affected_rows(); $rcode = 1; } else { $num_rows = 0; } $rarg = $num_rows; } // -- process "insert" operation -- else if ($operation == "insert") { $valuesNode = $nodeOperation->getElementsByTagName("values"); $valueNode = $valuesNode->item(0); // Check the id $arg = $valueNode->getAttribute("mls_id"); $num_rows = 1; if ($arg != NULL && $arg != "") { $query = "SELECT `mls_id` FROM listing where `mls_id` = " . formatString($arg); // Exec query $result = mysql_query($query); if ($result) { $num_rows = mysql_num_rows($result); } } else { $rcode = -1; $errmsg = "Bad mls_id"; } if ($num_rows == 1) { $rcode = -1; $errmsg = "This property already exists: ".$arg; } else { // -- Create the insert statement -- $insertNames = ""; $insertValues = ""; if ($valueNode->hasAttributes()) { $addStmt = ""; foreach ($valueNode->attributes as $attribute) { $name = $attribute->name; $checkName = ";".$name; $value = $attribute->value; // $insertNames = $insertNames . $addStmt . "`" . $name . "`"; // if (strpos(";mls_id;address;city;state;zipcode;status;stories;type;remarks;listedOn;", $checkName) === false) { // number $insertValues = $insertValues . $addStmt . mysql_escape_string($value); } else { // string $insertValues = $insertValues . $addStmt . formatString($value); } $addStmt = ","; } } $query = "INSERT INTO listing (" . $insertNames . ") VALUES (" . $insertValues . ")"; // -- Exec query -- $result = mysql_query($query); if ($result) { $num_rows = mysql_affected_rows(); $rcode = 1; } else { $num_rows = 0; } // -- $rarg = $num_rows; } } else { $operation = "badoperation"; } mysql_close(); // ----- Send XML ----- $rootNode->setAttribute("operation", $operation); $rootNode->setAttribute("arg", $arg); $rootNode->setAttribute("rcode", $rcode); $rootNode->setAttribute("rarg", $rarg); $rootNode->setAttribute("errmsg", $errmsg); // print the XML print $dom->saveXML(); ?>
No entiendo mucho de php, pero se que el error está en la función new DOMDocument, si tiene algún truco para pasar el código seria genial.
Gracias,
Tom