Index: extensions/EStat/lib/statDB.class.inc.php
===================================================================
--- extensions/EStat/lib/statDB.class.inc.php	(revision 17737)
+++ extensions/EStat/lib/statDB.class.inc.php	(revision 17758)
@@ -193,9 +193,10 @@
    *
    * @param String $file
+   * @param Boolean $force: if true, $force the filename affectation even if file doesn't exist
    * @return String: file name set
    */
-  public function setIpCountryFile($file)
-  {
-    if(file_exists($file))
+  public function setIpCountryFile($file, $force=false)
+  {
+    if($force or file_exists($file))
       $this->ipCountryFile=$file;
     return($this->ipCountryFile);
@@ -728,4 +729,5 @@
             break;
           case 'between':
+          case 'not between':
             if($field=='IPadress')
             {
@@ -737,5 +739,5 @@
               $num++;
             }
-            $where[]=' '.$field." BETWEEN ".$param['minValue']." AND ".$param['maxValue']." ";
+            $where[]=' '.$field.' '.strtoupper($param['operator']).' '.$param['minValue']." AND ".$param['maxValue']." ";
             break;
         }
@@ -824,4 +826,41 @@
   }
 
+
+  /**
+   * to be used with IP filter: replace the given operator with 'between' or 'not between'
+   *
+   * @param Array $value
+   * @return Array
+   */
+  protected function checkIPFilter($value)
+  {
+    if(is_array($value))
+    {
+      if(isset($value['operator']))
+      {
+        if($value['operator']=='=' or
+           $value['operator']=='>' or
+           $value['operator']=='>=' or
+           $value['operator']=='<' or
+           $value['operator']=='<=' or
+           $value['operator']=='like')
+        {
+          $value['operator']='between';
+          $value['minValue']=$value['value'];
+          $value['maxValue']=$value['value'];
+          $value['value']=null;
+        }
+        elseif($value['operator']=='!=' or
+               $value['operator']=='not like')
+        {
+          $value['operator']='not between';
+          $value['minValue']=$value['value'];
+          $value['maxValue']=$value['value'];
+          $value['value']=null;
+        }
+      }
+    }
+    return($value);
+  } // checkIPFilter
 
 
@@ -856,4 +895,6 @@
           case '<=':
           case '!=':
+          case 'like':
+          case 'not like':
             if(isset($value['value']))
             {
@@ -866,5 +907,6 @@
                   break;
                 case 'IP':
-                  $value['value']=$this->checkValueIP($value['value']);
+                  // for IP, replace internaly the operator with a 'between'
+                  $value['value']=$this->checkValueIP($value['value'], 0);
                   if($value['value']==null) return(null);
                   break;
@@ -893,5 +935,5 @@
                     break;
                   case 'IP':
-                    $val=$this->checkValueIP($val);
+                    $val=$this->checkValueIP($val, 0);
                     if($val!=null) $returned[]=$val;
                     break;
@@ -910,4 +952,5 @@
             break;
           case 'between':
+          case 'not between':
             if(isset($value['minValue']) and  isset($value['maxValue']))
             {
@@ -921,7 +964,7 @@
                   break;
                 case 'IP':
-                  $value['minValue']=$this->checkValueIP($value['minValue']);
+                  $value['minValue']=$this->checkValueIP($value['minValue'], 0);
                   if($value['minValue']==null) return(null);
-                  $value['maxValue']=$this->checkValueIP($value['maxValue']);
+                  $value['maxValue']=$this->checkValueIP($value['maxValue'], 255);
                   if($value['maxValue']==null) return(null);
                   break;
@@ -981,9 +1024,10 @@
    *
    * @param String $value
+   * @param Integer $completeCode
    * @return String
    */
-  protected function checkValueIP($value)
-  {
-    $returned=self::IPBinaryEncode($value);
+  protected function checkValueIP($value, $completeCode=0)
+  {
+    $returned=self::IPBinaryEncode($value, $completeCode);
     if($returned=="\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") return(null);
     return($returned);
@@ -1000,13 +1044,16 @@
    *
    * @param String $IP: text IP string
+   * @param Integer $completeCode
    * @return String: a binary string
    */
-  static public function IPBinaryEncode($IP)
+  static public function IPBinaryEncode($IP, $completeCode=0)
   {
     $value=trim($IP);
-    if(preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i',$value)>0)
+    if(preg_match('/\d{1,3}(\.\d{1,3}(\.\d{1,3}(\.\d{1,3})?)?)?/i',$value)>0)
     {
       //IPv4
       $tmp=explode('.',$value);
+      while(count($tmp)<4) $tmp[]=$completeCode;
+
       return("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".chr($tmp[0]+0).chr($tmp[1]+0).chr($tmp[2]+0).chr($tmp[3]+0));
     }
@@ -1088,7 +1135,21 @@
 
 
-
-
-
+/*
+ used to display binary values when debug is necessary...
+
+function toHexDump($data)
+  {
+    $returned="";
+    $maxItems=strlen($data);
+
+    $tmp=array();
+    for($i=0;$i<$maxItems;$i++)
+    {
+      $tmp[]=sprintf("%02x", ord($data{$i}));
+    }
+    $returned.=implode(" ", $tmp);
+    return($returned);
+  }
+*/
 
 
