Moving 2.0 development version to main trunk.
[fa-stable.git] / includes / data_checks.inc
index ef33acfdfd4d329412a7461586c07488f20b526a..b79bf3d2357d7c5cc3981331cf06cf82728ccccd 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 function db_has_customers()
 {
        return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."debtors_master");
@@ -130,7 +129,7 @@ function check_db_has_bank_trans_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");
+       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE debtor_no='$customer_id'");
 }
 
 function db_has_customer_branches()
@@ -428,5 +427,38 @@ function check_empty_result($sql)
        $myrow = db_fetch_row($result);
        return $myrow[0] > 0;           
 }
+//
+//     Integer input check 
+//     Return 1 if number has proper form and is within <min, max> range
+//
+function check_int($postname, $min=null, $max=null) {
+       if(!isset($_POST[$postname]))
+         return 0;
+    $num = input_num($postname);
+    if(!is_int($num)) 
+         return 0;
+    if (isset($min) && ($num<$min)) 
+         return 0;
+    if (isset($max) && ($num>$max)) 
+         return 0;
+    return 1;
+}
+//
+//     Numeric input check.
+//     Return 1 if number has proper form and is within <min, max> range
+//
+function check_num($postname, $min=null, $max=null) {
+       if(!isset($_POST[$postname]))
+         return 0;
+    $num = input_num($postname);
+    if ($num === false) 
+         return 0;
+    if (isset($min) && ($num<$min)) 
+         return 0;
+    if (isset($max) && ($num>$max)) 
+         return 0;
+    return 1;
+}
+
 
 ?>
\ No newline at end of file