UpdateCurrencyRate.php
[Pman.Core] / UpdateCurrencyRate.php
index d6213e0..433f07c 100644 (file)
@@ -58,17 +58,17 @@ class Pman_Core_UpdateCurrencyRate extends Pman
         $fromDate = date('m/d/y', strtotime("-6 MONTH"));
         $toDate = date('m/d/y');
         
-        foreach ($currency as $c){
+        foreach ($currency as $k => $c){
             $params = array(
-                'lang' => 'en',
-                'result' => 1,
-                'date1' => $fromDate,
-                'date'=> $toDate,
-                'date_fmt' => 'us',
-                'exch' => $c,
-                'expr' => 'USD',
-                'margin_fixed' => 0,
-                'format'=> 'HTML'
+                'lang'          => 'en',
+                'result'        => 1,
+                'date1'         => $fromDate,
+                'date'          => $toDate,
+                'date_fmt'      => 'us',
+                'exch'          => $c,
+                'expr'          => 'USD',
+                'margin_fixed'  => 0,
+                'format'        => 'HTML'
             );
             
             $response = $this->curl($this->actionUrl, $params, 'POST');
@@ -96,16 +96,16 @@ class Pman_Core_UpdateCurrencyRate extends Pman
                 $o = clone($curr);
             }
             
-            $curr->setForm(array(
-                'rate' => $rate,
-                'from' => 
-                
+            $curr->setFrom(array(
+                'rate'  => $rate,
+                'from'  => date('Y-m-d H:i:s', strtotime($fromDate)),
+                'to'    => date('Y-m-d H:i:s', strtotime($toDate))
             ));
 
+            (empty($o)) ? $curr->insert() : $curr->update($o);
+            
         }
         
-        
-        
     }
     
     function curl($url, $request = array(), $method = 'GET')