<?php
$query = new WA_MySQLi_RS("query",$localhost,0);
$query->setQuery("SELECT * from ((SELECT agreement_typesID, agreement_name, state, description, category as thecategory, latest, public, concat('https://sdpc.a4l.org/agreements/',file_pdf) as agreement_file_pdf, concat('https://sdpc.a4l.org/agreements/',file_doc) as agreement_file_doc FROM agreement_types where state = ? and agreement_typesID = ? and category = ?) t1 left join (SELECT * FROM agreement_vendor_types) t8 on (t1.agreement_typesID = t8.agreement_typesID) left join (SELECT * from clause_agreement_type) t2 on (t1.agreement_typesID = t2.agreement_typesID or t2.agreement_type_vendorID = t8.agreement_type_vendorID) left join (SELECT * from contract_clauses) t3 on (t3.clauseID = t2.clauseID) left join (select * from clause_obligation) t4 on (t4.clause_agreement_typeID = t2.clause_agreement_typeID) left join (SELECT * from obligations) t5 on (t5.obligationID = t4.obligationID) left join (SELECT * from obligation_benchmark) t6 on (t4.clause_obligationID = t6.clause_obligationID) left join (SELECT *, benchmarkID as thebenchmarkID from benchmarks) t7 on (t6.benchmarkID = t7.benchmarkID))");
$query->bindParam("i", "".($_GET['state']) ."", "-1"); //state
$query->bindParam("i", "".($_GET['agreement_typesID']); //agreement_typesID
$query->bindParam("i", "".($_GET['category']) ."", "-1"); //category
$query->execute();
?>
<?php
function to_xml(SimpleXMLElement $object, array $row) {
foreach ($row as $key => $value) {
if (is_array($value)) {
$new_object = $object->addChild($key);
to_xml($new_object, $value);
} else {
// if the key is an integer, it needs text with it to actually work.
if ($key == (int) $key) {
$key = "$key";
}
$object->addChild($key, $value);
}
}
}
?>
<?php
ob_start();
while (!$query->atEnd()) {
$xml = new SimpleXMLElement('<data/>');
to_xml($xml, $query->Results[$query->Index]);
print $xml->asXML();
$query->moveNext();
}
$output = ob_get_contents();
ob_end_clean();
header('Content-Type: application/xml; charset=utf-8');
header('Content-Language: en');
header('Cache-Control: no-store, no-cache, must-revalidate');
header("Content-Length: ".strlen($output));
header("Date: ".gmdate('D, d M Y H:i:s T'));
echo($output);
?>