Fixed slash quotation problems on direct POST var reuse.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 11 Sep 2008 21:57:20 +0000 (21:57 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 11 Sep 2008 21:57:20 +0000 (21:57 +0000)
includes/db/connect_db.inc
includes/session.inc
includes/ui/ui_view.inc

index f7d214beb8b8904ccd8ed8ba8ba60370efdbaf50..3fc2bcfb437a9a7bdcb270cd511bade59bbe5de1 100644 (file)
@@ -79,8 +79,6 @@ function db_escape($value = "", $nullify = false)
 
        //reset default if second parameter is skipped
        $nullify = ($nullify === null) ? (false) : ($nullify);
-       //undo slashes for poorly configured servers
-       $value = (get_magic_quotes_gpc()) ? (stripslashes($value)) : ($value);
 
        //check for null/unset/empty strings
        if ((!isset($value)) || (is_null($value)) || ($value === "")) {
index 9089c693111ead3c2a6a29688c74afb378ddfae4..0e7d31138d0d35d32eb9e774fad08fcddc5584fe 100644 (file)
                }
        }
 
+       //-----------------------------------------------------------------------------
+       //      Removing magic quotes from nested arrays/variables
+       //
+       function strip_quotes($data)
+       {
+               if(get_magic_quotes_gpc()) {
+                       if(is_array($data)) {
+                               foreach($data as $k => $v) {
+                                       $data[$k] = strip_quotes($data[$k]);
+                               }
+                       } else
+                               return stripslashes($data);
+               }
+               return $data;
+       }
+
+
        //----------------------------------------------------------------------------------------
        if (!isset($_SESSION["wa_current_user"]) ||
                (isset($_SESSION["wa_current_user"]) && !$_SESSION["wa_current_user"]->logged_in()))
 
        check_page_security($page_security);
 
-
+// POST vars cleanup needed for direct reuse.
+// We quote all values later with db_escape() before db update.
+       $_POST = strip_quotes($_POST);
 
 ?>
\ No newline at end of file
index 7ca792aee8e30cd76afdd4a81d76d7f4bc888f4e..c1364786608d52b4c08b636ec818a561e3196f14 100644 (file)
@@ -286,10 +286,17 @@ function exchange_rate_display($from_currency, $to_currency, $date_, $buttons=tr
                        else
                                $currency = $from_currency;
                        $rate = get_ecb_rate($currency);
-                       if (get_date_exchange_rate($currency, $date_))
-                               update_exchange_rate($currency, $date_, $rate, $rate);
-                       else
-                               add_exchange_rate($currency, $date_, $rate, $rate);
+                       if ($rate==0) 
+                       {
+                               display_error(_("Cannot get exchange rate for this currency. Please add exchange rate manually on Exchange Rates page.") );
+                               $rate = get_exchange_rate_from_to($to_currency, $from_currency, $date_);
+                       } else 
+                       {
+                               if (get_date_exchange_rate($currency, $date_))
+                                       update_exchange_rate($currency, $date_, $rate, $rate);
+                               else
+                                       add_exchange_rate($currency, $date_, $rate, $rate);
+                       }
                        if ($from_currency == $comp_currency)
                                $rate = 1 / $rate;
                        $Ajax->activate('get_rate');