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 //            exch2:
40             'expr' => 'USD',
41 //            expr2:
42             'margin_fixed' => 0,
43             'format'=> 'HTML',
44 //            SUBMIT:Get Table
45         );
46         
47     }
48     
49     function curl($url, $request = array(), $method = 'GET') 
50     {
51          
52         if(is_array($request)){
53             $request = http_build_query($request);
54         }
55         
56         $url = $url . ($method == 'GET' ? "?" . $request : '');  
57         $ch = curl_init($url);
58         
59         if ($method == 'POST') {
60             curl_setopt($ch, CURLOPT_POST, 1);
61             curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
62             curl_setopt($ch, CURLOPT_HTTPHEADER,
63                     array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
64         }
65         
66         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
67         
68         curl_setopt($ch, CURLOPT_HEADER, false);
69         curl_setopt($ch, CURLOPT_VERBOSE, 1);
70         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
71         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
72
73         $response = curl_exec($ch);
74
75         curl_close($ch);
76         
77         return $response;
78     }
79     
80     /*
81     lang:en
82     result:1
83     date1:10/14/14
84     date:10/20/14
85     date_fmt:us
86     exch:USD
87     exch2:
88     expr:EUR
89     expr2:
90     margin_fixed:0
91     format:HTML
92     SUBMIT:Get Table
93     */
94 }