Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <?php
  2. error_reporting(-1);
  3. ini_set('display_errors', 'On');
  4. ini_set("allow_url_fopen", 1);
  5.  
  6. class postXML{
  7. protected $file;
  8. protected $oldRate;
  9. protected $name;
  10. protected $loc;
  11.  
  12. public function getFile(){
  13. $this->file = new SimpleXMLElement('currencies.xml', NULL, TRUE);
  14. }
  15.  
  16. public function postCurr(){
  17. $code = $this->file->xpath("currency[@code='".$_POST["code"]."']");
  18. $this->oldRate = $code[0]->attributes()->rate;
  19. $this->name = $code[0]->children('name');
  20. foreach($code[0]->children('location') as $child){
  21. $this->loc = $this->loc.",".$child;
  22. }
  23. $code[0]->attributes()->time = date("l, d m Y h:i:sa");
  24. $code[0]->attributes()->rate = $_POST['rate'];
  25. $this->file->asXML('currencies.xml');
  26. }
  27.  
  28. public function responseXML(){
  29. $xml = new SimpleXMLElement('<method/>');
  30. $xml->addAttribute('type', 'post');
  31. $xml->addChild('at', date('l, d m Y h:i:sa'));
  32. $prev = $xml->addChild('previous');
  33. $prev->addChild('rate', $this->oldRate);
  34. $pCurr = $prev->addChild('curr');
  35. $pCurr->addChild('code', $_POST['code']);
  36. $pCurr->addChild('name', $this->name);
  37. $pCurr->addChild('loc', $this->loc);
  38. $new = $xml->addChild('new');
  39. $new->addChild('rate', $_POST['rate']);
  40. $nCurr = $new->addChild('curr');
  41. $nCurr->addChild('code', $_POST['code']);
  42. $nCurr->addChild('name', $this->name);
  43. $nCurr->addChild('loc', $this->loc);
  44. echo $xml->asXML();
  45. header('Content-Type: text/xml');
  46. }
  47. }
  48.  
  49. $postXML = new postXML;
  50. $postXML->getFile();
  51. $postXML->postCurr();
  52. $postXML->responseXML();
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement