Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1);
- ini_set('display_errors', 'On');
- ini_set("allow_url_fopen", 1);
- class postXML{
- protected $file;
- protected $oldRate;
- protected $name;
- protected $loc;
- public function getFile(){
- $this->file = new SimpleXMLElement('currencies.xml', NULL, TRUE);
- }
- public function postCurr(){
- $code = $this->file->xpath("currency[@code='".$_POST["code"]."']");
- $this->oldRate = $code[0]->attributes()->rate;
- $this->name = $code[0]->children('name');
- foreach($code[0]->children('location') as $child){
- $this->loc = $this->loc.",".$child;
- }
- $code[0]->attributes()->time = date("l, d m Y h:i:sa");
- $code[0]->attributes()->rate = $_POST['rate'];
- $this->file->asXML('currencies.xml');
- }
- public function responseXML(){
- $xml = new SimpleXMLElement('<method/>');
- $xml->addAttribute('type', 'post');
- $xml->addChild('at', date('l, d m Y h:i:sa'));
- $prev = $xml->addChild('previous');
- $prev->addChild('rate', $this->oldRate);
- $pCurr = $prev->addChild('curr');
- $pCurr->addChild('code', $_POST['code']);
- $pCurr->addChild('name', $this->name);
- $pCurr->addChild('loc', $this->loc);
- $new = $xml->addChild('new');
- $new->addChild('rate', $_POST['rate']);
- $nCurr = $new->addChild('curr');
- $nCurr->addChild('code', $_POST['code']);
- $nCurr->addChild('name', $this->name);
- $nCurr->addChild('loc', $this->loc);
- echo $xml->asXML();
- header('Content-Type: text/xml');
- }
- }
- $postXML = new postXML;
- $postXML->getFile();
- $postXML->postCurr();
- $postXML->responseXML();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement