Some more work in progress on multiple grouping by.
[timetracker.git] / WEB-INF / lib / common.lib.php
index 629e7d7..d29ba1a 100644 (file)
@@ -319,7 +319,7 @@ function ttValidCondition($val, $emptyValid = true)
   if (stristr($val, '<script>') || stristr($val, '<script '))
     return false;
 
-  if (!preg_match("/^count\s?>\s?\d+$/", $val))
+  if (!preg_match("/^count\s?(=|[<>]=?|<>)\s?\d+$/", $val))
     return false;
 
   return true;
@@ -332,8 +332,8 @@ function ttValidCondition($val, $emptyValid = true)
 function ttValidIP($val, $emptyValid = false)
 {
   $val = trim($val);
-  if (strlen($val) == 0 && !$emptyValid)
-    return false;
+  if (strlen($val) == 0 && $emptyValid)
+    return true;
 
   $subnets = explode(',', $val);
   foreach ($subnets as $subnet) {
@@ -383,3 +383,18 @@ function ttAccessAllowed($required_right)
 
   return false;
 }
+
+// ttStartsWith functions checks if a string starts with a given substring.
+function ttStartsWith($string, $startString)
+{
+    $len = strlen($startString);
+    return (substr($string, 0, $len) === $startString);
+}
+
+// ttDateToUserFormat converts a date from database format to user format.
+function ttDateToUserFormat($date)
+{
+  global $user;
+  $o_date = new DateAndTime(DB_DATEFORMAT, $date);
+  return $o_date->toString($user->date_format);
+}