X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fdata_checks.inc;h=67768b937df6d1f3eff7662b8258b76fa71e7ece;hb=8a2ac7536a58c7860cbebba4f786f51f761ac2bf;hp=295a353e1203d2ec1cc484291803d9e8113f7fe7;hpb=ebc600101ceab69c06eac4b1bd4d1782af45de05;p=fa-stable.git diff --git a/includes/data_checks.inc b/includes/data_checks.inc index 295a353e..67768b93 100644 --- a/includes/data_checks.inc +++ b/includes/data_checks.inc @@ -41,6 +41,19 @@ function check_db_has_currencies($msg) } } +function db_has_currency_rates($currency, $date_, $msg=false) +{ + $date = date2sql($date_); + + if (is_company_currency($currency)) + return 1; + $ret = check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."exchange_rates WHERE curr_code = '$currency' && date_ <= '$date'"); + if ($ret == 0 && $msg) + display_error(sprintf(_("Cannot retrieve exchange rate for currency %s as of %s. Please add exchange rate manually on Exchange Rates page."), + $currency, $date_), true); + return $ret; +} + function db_has_sales_types() { return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."sales_types"); @@ -124,7 +137,7 @@ function check_db_has_movement_types($msg) function db_customer_has_branches($customer_id) { return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch " - ."WHERE debtor_no='$customer_id'"); + ."WHERE debtor_no=".db_escape($customer_id)); } function db_has_customer_branches() @@ -430,7 +443,7 @@ function db_has_quick_entries() function db_has_tags($type) { - return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tags WHERE type=$type"); + return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tags WHERE type=".db_escape($type)); } function check_db_has_tags($type, $msg) @@ -449,7 +462,7 @@ function check_empty_result($sql) $result = db_query($sql, "could not do check empty query"); $myrow = db_fetch_row($result); - return $myrow[0] > 0; + return $myrow[0] > 0; } // // Integer input check @@ -470,12 +483,13 @@ function check_int($postname, $min=null, $max=null) { // // Numeric input check. // Return 1 if number has proper form and is within range +// Empty/not defined fields are defaulted to $dflt value. // -function check_num($postname, $min=null, $max=null) { +function check_num($postname, $min=null, $max=null, $dflt=0) { if(!isset($_POST[$postname])) return 0; - $num = input_num($postname); - if ($num === false) + $num = input_num($postname, $dflt); + if ($num === false || $num === null) return 0; if (isset($min) && ($num<$min)) return 0;