Replaced the global variables for table styles to defined CSS classes.
[fa-stable.git] / gl / manage / exchange_rates.php
index 2592b0cc01eaa93cb6a01ef9e7c5e4dc45cbfd6e..eaa0796f0cf518ab6d65b97b6f0f336ba9c7adf0 100644 (file)
@@ -9,8 +9,8 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-$page_security = 9;
-$path_to_root="../..";
+$page_security = 'SA_EXCHANGERATE';
+$path_to_root = "../..";
 include($path_to_root . "/includes/db_pager.inc");
 include_once($path_to_root . "/includes/session.inc");
 
@@ -21,7 +21,7 @@ include_once($path_to_root . "/includes/banking.inc");
 $js = "";
 if ($use_date_picker)
        $js .= get_js_date_picker();
-page(_("Exchange Rates"), false, false, "", $js);
+page(_($help_context = "Exchange Rates"), false, false, "", $js);
 
 simple_page_mode(false);
 
@@ -40,7 +40,12 @@ function check_data()
                set_focus('BuyRate');
                return false;
        }
-
+       if (get_date_exchange_rate($_POST['curr_abrev'], $_POST['date_']))
+       {
+               display_error( _("The exchange rate for the date is already there."));
+               set_focus('date_');
+               return false;
+       }
        return true;
 }
 
@@ -67,6 +72,7 @@ function handle_submit()
        }
 
        $selected_id = '';
+       clear_data();
 }
 
 //---------------------------------------------------------------------------------------------
@@ -79,6 +85,7 @@ function handle_delete()
                return;
        delete_exchange_rate($selected_id);
        $selected_id = '';
+       clear_data();
 }
 
 //---------------------------------------------------------------------------------------------
@@ -94,7 +101,6 @@ function del_link($row)
 
 function display_rates($curr_code)
 {
-       global $table_style;
 
 }
 
@@ -102,9 +108,9 @@ function display_rates($curr_code)
 
 function display_rate_edit()
 {
-       global $selected_id, $table_style2, $Ajax;
+       global $selected_id, $Ajax;
 
-       start_table($table_style2);
+       start_table(TABLESTYLE2);
 
        if ($selected_id != "")
        {
@@ -128,7 +134,8 @@ function display_rate_edit()
        }
        if (isset($_POST['get_rate']))
        {
-               $_POST['BuyRate'] = exrate_format(get_ecb_rate($_POST['curr_abrev']));
+               $_POST['BuyRate'] = 
+                       exrate_format(retrieve_exrate($_POST['curr_abrev'], $_POST['date_']));
                $Ajax->activate('BuyRate');
        }
        small_amount_row(_("Exchange Rate:"), 'BuyRate', null, '',
@@ -171,7 +178,7 @@ if (!isset($_POST['curr_abrev']))
 
 echo "<center>";
 echo _("Select a currency :") . "  ";
-currencies_list('curr_abrev', null, true);
+echo currencies_list('curr_abrev', null, true);
 echo "</center>";
 
 // if currency sel has changed, clear the form
@@ -183,10 +190,7 @@ if ($_POST['curr_abrev'] != get_global_curr_code())
 
 set_global_curr_code($_POST['curr_abrev']);
 
-$sql = "SELECT date_, rate_buy, id FROM "
-       .TB_PREF."exchange_rates "
-       ."WHERE curr_code='".$_POST['curr_abrev']."'
-        ORDER BY date_ DESC";
+$sql = get_sql_for_exchange_rates();
 
 $cols = array(
        _("Date to Use From") => 'date', 
@@ -206,11 +210,9 @@ else
 {
 
        br(1);
-       if (list_updated('curr_abrev')) {
-               $table->set_sql($sql);
-               $table->set_columns($cols);
-       }
        $table->width = "40%";
+       if ($table->rec_count == 0)
+               $table->ready = false;
        display_db_pager($table);
        br(1);
     display_rate_edit();