openMemory(); $this->setIndent(true); $this->setIndentString(' '); $this->startDocument('1.0', 'UTF-8'); $this->startElement('mds'); $this->startElement('auth'); $this->writeElement('login', $auth['login']); $this->writeElement('pass', $auth['pass']); $this->endElement(); // $this->startElement('request'); $this->writeElement('type', $type); $this->startElement('conditions'); if (is_array($params)) foreach ($params as $pkey=>$pvalue) $this->writeElement($pkey, $pvalue); $this->endElement(); // if (isset($formdata) && is_array($formdata) && count($formdata)) { $this->write_array_to_xml('forminfo', $formdata); } $this->endElement(); // $this->endElement(); // return $this->outputMemory(true); } public function sendXML($rqxml) { $c = curl_init('http://mdsws.merlinx.pl/bookV3/'); curl_setopt($c, CURLOPT_POST, true); curl_setopt($c, CURLOPT_POSTFIELDS, $rqxml); curl_setopt($c, CURLOPT_ENCODING, 'gzip'); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $res = curl_exec($c); curl_close($c); return $res; } private function write_array_to_xml($inpname, $inpvalue) { if (is_numeric($inpname)) $inpname = 'data'; if (is_array($inpvalue)) { $this->startElement($inpname); foreach ($inpvalue as $ikey=>$ivalue) $this->write_array_to_xml($ikey,$ivalue); $this->endElement(); } else $this->writeElement($inpname, $inpvalue); } /** * @param SimpleXML object */ public function processFormData(&$xml) { $resarr = array(); if (count($xml->children())) { foreach ($xml->children() as $nname => $child) { switch ($nname) { case 'data': $resarr[] = $this->processFormData($child); break; default: $resarr[$nname] = $this->processFormData($child); break; } } } else $resarr = (string)$xml; return $resarr; } /** * @param Array */ public function filterFormValues($arr) { if (is_array($arr) && count($arr)) { if (isset($arr['value'])) $arr = $arr['value']; elseif (isset($arr['selected'])) $arr = $arr['selected']; elseif (isset($arr['values'])) $arr = $arr['values'][0]; else { foreach ($arr as $key=>$value) $arr[$key] = $this->filterFormValues($value); } } return $arr; } } ?>