UpdateCurrencyRate.php
[Pman.Core] / UpdateCurrencyRate.php
1 <?php
2
3 require_once 'Pman.php';
4
5 class Pman_Core_UpdateCurrencyRate extends Pman
6 {
7     
8     static $cli_desc = "Update Currency Exchange Rate";
9     
10     static $cli_opts = array();
11     
12     var $cli = false; 
13     
14     var $actionUrl = 'http://www.oanda.com/currency/historical-rates-classic';
15     
16     
17     function getAuth() 
18     {
19         $ff = HTML_FlexyFramework::get();
20         if (!empty($ff->cli)) {
21             $this->cli = true;
22             return true;
23         }
24         
25         die("NOT ALLOWED");
26     }
27     
28     function get()
29     {
30         echo"'update currency exchange rate \n";
31         
32         $params = array(
33             'lang' => 'en',
34             'result' => 1,
35             'date1' => '10/14/14',
36             'date'=> '10/20/14',
37             'date_fmt' => 'us',
38             'exch' => 'CNY',
39             'expr' => 'USD',
40             'margin_fixed' => 0,
41             'format'=> 'HTML'
42         );
43         
44         $response = $this->curl($this->actionUrl, $params, 'POST');
45         
46         file_put_contents('/tmp/test.html', $response);
47         
48     }
49     
50     function curl($url, $request = array(), $method = 'GET') 
51     {
52          
53         if(is_array($request)){
54             $request = http_build_query($request);
55         }
56         
57         $url = $url . ($method == 'GET' ? "?" . $request : '');  
58         $ch = curl_init($url);
59         
60         if ($method == 'POST') {
61             curl_setopt($ch, CURLOPT_POST, 1);
62             curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
63             curl_setopt($ch, CURLOPT_HTTPHEADER,
64                     array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
65         }
66         
67         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
68         
69         curl_setopt($ch, CURLOPT_HEADER, false);
70         curl_setopt($ch, CURLOPT_VERBOSE, 1);
71         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
72         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
73
74         $response = curl_exec($ch);
75
76         curl_close($ch);
77         
78         return $response;
79     }
80     
81     /*
82     lang:en
83     result:1
84     date1:10/14/14
85     date:10/20/14
86     date_fmt:us
87     exch:USD
88     exch2:
89     expr:EUR
90     expr2:
91     margin_fixed:0
92     format:HTML
93     SUBMIT:Get Table
94     */
95 }