Ajax Inquiry Fixes (Braatwaate).
[fa-stable.git] / includes / ui / ui_view.inc
index 389ea5302d389acb3a17b12996edd409656ade79..b65339ef8fc09cabceae106b4fa119550ddedbd3 100644 (file)
@@ -278,7 +278,7 @@ function exchange_rate_display($from_currency, $to_currency, $date_, $force_edit
 
        if ($from_currency != $to_currency)
        {
-               $rate = get_post('_ex_rate');
+               $rate = input_num('_ex_rate');
                if (check_ui_refresh() || !$rate) { // readonly or ui context changed
                        $comp_currency = get_company_currency();
                        if ($from_currency == $comp_currency)
@@ -1546,3 +1546,44 @@ function trans_editor_link($type, $trans_no)
                (is_closed_trans($type, $trans_no) ? set_icon(ICON_CLOSED, _('Closed')) :
                        pager_link(_("Edit"), sprintf($editor_url[$type], $trans_no, $type), ICON_EDIT));
 }
+
+// This script updates the browser history when
+// any of the passed variables change.
+// This way, if the user changes these variables,
+// then uses the back button to return, it returns to the page
+// as the user modified it.
+function get_js_history(...$vars)
+{
+    $js = ' 
+    function changeVar() {
+        var stateObj = { foo: "bar" };
+        var state = "";
+';
+
+    $first = true;
+    foreach ( $vars as $var ) {
+        $js .= '
+        var element = document.getElementsByName("' . $var. '");
+        if (element[0])';
+        if ($first) {
+            $first = false;
+            $js .= '
+            state += "' . basename($_SERVER['SCRIPT_NAME']) . "?";
+        } else
+            $js .= '
+            state += "&';
+        $js .= $var .'="' . ' + element[0].value;';
+    }
+
+    $js .= '
+        history.replaceState(stateObj, "page 2", state);
+    }';
+    return $js;
+}
+
+function set_posts(...$vars)
+{
+    foreach ( $vars as $var )
+        if (isset($_GET[$var]))
+            $_POST[$var] = $_GET[$var];
+}