Index: /extensions/AStat/astat_aim.class.inc.php
===================================================================
--- /extensions/AStat/astat_aim.class.inc.php	(revision 10263)
+++ /extensions/AStat/astat_aim.class.inc.php	(revision 10264)
@@ -16,17 +16,14 @@
 if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
 
-include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php');
+include_once('astat_root.class.inc.php');
 include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php');
 
-class AStat_AIM extends CommonPlugin
+class AStat_AIM extends AStat_root
 {
   protected $css = null;
 
-  function AStat_AIM($prefixeTable, $filelocation)
+  function __construct($prefixeTable, $filelocation)
   {
-    $this->setPluginName("AStat.2");
-    $this->setPluginNameFiles("astat");
     parent::__construct($prefixeTable, $filelocation);
-    $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css");
   }
 
@@ -39,165 +36,4 @@
   }
 
-
-  /*
-    initialization of config properties
-  */
-  function initConfig()
-  {
-    $this->config=array(
-      'AStat_BarColor_Pages' => '6666ff',
-      'AStat_BarColor_Img' => '66ff66',
-      'AStat_BarColor_IP' => 'ff6666',
-      'AStat_MouseOverColor' => '303030',
-      'AStat_NpIPPerPages' => '25',
-      'AStat_NpCatPerPages' => '50',
-      'AStat_MaxBarWidth' => '400',
-      'AStat_default_period' => 'global', //global, all, year, month, day
-      'AStat_ShowThumbCat' => 'true',
-      'AStat_DefaultSortCat' => 'page', //page, picture, nbpicture
-      'AStat_ShowThumbImg' => 'true',
-      'AStat_DefaultSortImg' => 'picture',  //picture, catname
-      'AStat_NbImgPerPages' => '100',
-      'AStat_BarColor_Cat' => 'fff966',
-      'AStat_DefaultSortIP' => 'page',    //page, ip, picture
-      'AStat_SeeTimeRequests' => 'false',
-      'AStat_BlackListedIP' => '',    // ip blacklisted (separator : ",")
-      'AStat_UseBlackList' => 'false'    // if false, blacklist usage is disabled, if "invert" then result are inverted
-      );
-
-  }
-
-  /*
-    surchage of CommonPlugin->saveConfig function
-  */
-  function loadConfig()
-  {
-    parent::loadConfig();
-    if(!$this->css->fileExists())
-    {
-      $this->css->makeCSS($this->generate_CSS());
-    }
-  }
-
-  /*
-    surchage of CommonPlugin->saveConfig function
-  */
-  function saveConfig()
-  {
-    if(parent::saveConfig())
-    {
-      $this->css->makeCSS($this->generate_CSS());
-      return(true);
-    }
-    return(false);
-  }
-
-  /*
-    generate the css code
-  */
-  function generate_CSS()
-  {
-    $text = ".AStatBar1, .AStatBar2, .AStatBar3, .AStatBar4, .AStatBarX {
-      border:0px;
-      height:8px;
-      display: block;
-      margin:0px;
-      padding:0px;
-      left:0;
-      position:relative;
-      }
-       .MiniSquare1, .MiniSquare2, .MiniSquare3, .MiniSquare4 {
-      border:0px;
-      height:8px;
-      width:8px;
-      margin:0px;
-      padding:0px;
-      }
-       .AStatBar1 { background-color:#".$this->config['AStat_BarColor_Pages']."; top:5px;  }
-       .AStatBar2 { background-color:#".$this->config['AStat_BarColor_Img']."; top:-3px; }
-       .AStatBar3 { background-color:#".$this->config['AStat_BarColor_IP']."; top:-3px;}
-       .AStatBar4 { background-color:#".$this->config['AStat_BarColor_Cat']."; top:-3px;}
-       .AStatBarX { background-color:transparent; top:-3px; height:1px; }
-       .MiniSquare1 { color:#".$this->config['AStat_BarColor_Pages'].";   }
-       .MiniSquare2 { color:#".$this->config['AStat_BarColor_Img'].";  }
-       .MiniSquare3 { color:#".$this->config['AStat_BarColor_IP']."; }
-       .MiniSquare4 { color:#".$this->config['AStat_BarColor_Cat']."; }
-       .StatTableRow:hover { background-color:#".$this->config['AStat_MouseOverColor']."; }
-       .formtable, .formtable P { text-align:left; display:block; }
-       .formtable tr { vertical-align:top; }
-       .window_thumb {
-      position:absolute;
-      border: none;
-      background: none;
-      left:0;
-      top:0;
-      margin:0px;
-      padding:0px;
-      z-index:100;
-      overflow:hidden;
-      visibility:hidden; }
-        .img_thumb {
-      border: solid 3px #ffffff;
-      background: #000000;
-      margin:0px;
-      padding:0px; }
-        .time_request {
-      font-size:83%;
-      text-align:right; }
-        .invisible { visibility:hidden; display:none; }
-      .littlefont { font-size:90%; }
-      table.littlefont th { padding:3px; }
-      table.littlefont td { padding:0px;padding-left:3px;padding-right:3px; }
-      #iplist { visibility:hidden; position:absolute; width:200px; z-index:1000; }
-      .iipsellistitem { float:right; }
-      #iipsellist { width:100%; font-family:monospace; }
-    ";
-
-    return($text);
-  }
-
-  /* ---------------------------------------------------------------------------
-  Function needed for plugin activation
-  --------------------------------------------------------------------------- */
-
-  /*
-    get 'section' enumeration from HISTORY_TABLE
-  */
-  function get_section_enum($add)
-  {
-    $returned=array('', false);
-    $sql = 'SHOW COLUMNS FROM '.HISTORY_TABLE.' LIKE "section"';
-    $result=pwg_query($sql);
-    if($result)
-    {
-      $row = pwg_db_fetch_assoc($result);
-      $list=substr($row['Type'], 5, strlen($row['Type'])-6);
-      $returned[0]=explode(',', $list);
-      if((strpos($list, "'$add'")===false)&&($add!=''))
-      { array_push($returned[0], "'$add'"); }
-      else
-      { $returned[1]=true; }
-      return($returned);
-    }
-  }
-
-  function alter_history_section_enum($section)
-  {
-    $sections=$this->get_section_enum('deleted_cat');
-    if(!$sections[1])
-    {
-      $enums=implode(',', $sections[0]);
-      $sql="ALTER TABLE ".HISTORY_TABLE."
-          CHANGE `section` `section`
-          ENUM (".$enums.") ;";
-      $result=pwg_query($sql);
-      if(!$result)
-      {
-        return(false);
-      }
-    }
-    return(true);
-  }
-
 } // AStat_Plugin class
 
Index: /extensions/AStat/astat_aip.class.inc.php
===================================================================
--- /extensions/AStat/astat_aip.class.inc.php	(revision 10263)
+++ /extensions/AStat/astat_aip.class.inc.php	(revision 10264)
@@ -15,9 +15,9 @@
 if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
 
-include_once('astat_aim.class.inc.php');
+include_once('astat_root.class.inc.php');
 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
 include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php');
 
-class AStat_AIP extends AStat_AIM
+class AStat_AIP extends AStat_root
 {
   protected $tabsheet;
@@ -65,5 +65,5 @@
   function initEvents()
   {
-    add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS'));
+    add_event_handler('loc_end_page_header', array(&$this, 'applyCSS'));
   }
 
@@ -73,4 +73,11 @@
   Public classe functions
   --------------------------------------------------------------------------- */
+
+  public function applyCSS()
+  {
+    GPCCore::addHeaderCSS(basename(dirname($this->getPluginNameFiles())), PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'css/'.$this->getPluginNameFiles().".css");
+  }
+
+
 
   /*
Index: /extensions/AStat/astat_install.class.inc.php
===================================================================
--- /extensions/AStat/astat_install.class.inc.php	(revision 10264)
+++ /extensions/AStat/astat_install.class.inc.php	(revision 10264)
@@ -0,0 +1,70 @@
+<?php
+/* -----------------------------------------------------------------------------
+  Plugin     : AStat.2
+  Author     : Grum
+    email    : grum@piwigo.org
+    website  : http://photos.grum.fr
+
+    << May the Little SpaceFrog be with you ! >>
+  ------------------------------------------------------------------------------
+  See main.inc.php for release information
+
+  AStat_install classe => manage install process
+
+  --------------------------------------------------------------------------- */
+  include_once('astat_version.inc.php');
+  include_once('astat_root.class.inc.php');
+
+  class AStat_install extends AStat_root
+  {
+    /**
+     * function for installation process
+     *
+     * @return Bool : true if install process is ok, otherwise false
+     */
+    public function install()
+    {
+      $this->initConfig();
+      $this->loadConfig();
+      $this->config['installed']=ASTAT_VERSION2;
+      $this->config['newInstall']='y';
+      $this->saveConfig();
+
+      GPCCore::register($this->getPluginName(), ASTAT_VERSION, ASTAT_GPC_NEEDED);
+
+      return(true);
+    }
+
+
+    /**
+     * function for uninstall process
+     */
+    public function uninstall()
+    {
+      $this->deleteConfig();
+      GPCCore::unregister($this->getPluginName());
+    }
+
+    public function activate()
+    {
+      global $template;
+
+      $this->initConfig();
+      $this->loadConfig();
+      $this->config['newInstall']='n';
+      $this->config['installed']=ASTAT_VERSION2; //update the installed release number
+      $this->saveConfig();
+
+      GPCCore::register($this->getPluginName(), ASTAT_VERSION, ASTAT_GPC_NEEDED);
+
+      $this->alter_history_section_enum('deleted_cat');
+    }
+
+    public function deactivate()
+    {
+      $this->initConfig();
+      $this->loadConfig();
+    }
+  } //class
+
+?>
Index: /extensions/AStat/astat_root.class.inc.php
===================================================================
--- /extensions/AStat/astat_root.class.inc.php	(revision 10264)
+++ /extensions/AStat/astat_root.class.inc.php	(revision 10264)
@@ -0,0 +1,209 @@
+<?php
+/* -----------------------------------------------------------------------------
+  Plugin     : AStat.2
+  Author     : Grum
+    email    : grum@piwigo.org
+    website  : http://photos.grum.fr
+
+    << May the Little SpaceFrog be with you ! >>
+  ------------------------------------------------------------------------------
+  See main.inc.php for release information
+
+  AStat_install classe => manage install process
+
+  --------------------------------------------------------------------------- */
+
+if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
+
+include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php');
+include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php');
+
+
+class AStat_root extends CommonPlugin
+{
+  protected $css;   //the css object
+
+  public function __construct($prefixeTable, $filelocation)
+  {
+    global $conf;
+
+    $this->setPluginName("AStat.2");
+    $this->setPluginNameFiles("astat");
+    parent::__construct($prefixeTable, $filelocation);
+    $this->css = new GPCCss(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'css/'.$this->getPluginNameFiles().".css");
+  }
+
+  public function __destruct()
+  {
+    unset($this->css);
+    parent::__destruct();
+  }
+
+
+
+  /*
+    initialization of config properties
+  */
+  function initConfig()
+  {
+    $this->config=array(
+      'AStat_BarColor_Pages' => '6666ff',
+      'AStat_BarColor_Img' => '66ff66',
+      'AStat_BarColor_IP' => 'ff6666',
+      'AStat_MouseOverColor' => '303030',
+      'AStat_NpIPPerPages' => '25',
+      'AStat_NpCatPerPages' => '50',
+      'AStat_MaxBarWidth' => '400',
+      'AStat_default_period' => 'global', //global, all, year, month, day
+      'AStat_ShowThumbCat' => 'true',
+      'AStat_DefaultSortCat' => 'page', //page, picture, nbpicture
+      'AStat_ShowThumbImg' => 'true',
+      'AStat_DefaultSortImg' => 'picture',  //picture, catname
+      'AStat_NbImgPerPages' => '100',
+      'AStat_BarColor_Cat' => 'fff966',
+      'AStat_DefaultSortIP' => 'page',    //page, ip, picture
+      'AStat_SeeTimeRequests' => 'false',
+      'AStat_BlackListedIP' => '',    // ip blacklisted (separator : ",")
+      'AStat_UseBlackList' => 'false'    // if false, blacklist usage is disabled, if "invert" then result are inverted
+      );
+
+  }
+
+  /*
+    surchage of CommonPlugin->saveConfig function
+  */
+  function loadConfig()
+  {
+    parent::loadConfig();
+    if(!$this->css->fileExists())
+    {
+      $this->css->makeCSS($this->generate_CSS());
+    }
+  }
+
+  /*
+    surchage of CommonPlugin->saveConfig function
+  */
+  function saveConfig()
+  {
+    if(parent::saveConfig())
+    {
+      $this->css->makeCSS($this->generate_CSS());
+      return(true);
+    }
+    return(false);
+  }
+
+  /*
+    generate the css code
+  */
+  function generate_CSS()
+  {
+    $text = ".AStatBar1, .AStatBar2, .AStatBar3, .AStatBar4, .AStatBarX {
+      border:0px;
+      height:8px;
+      display: block;
+      margin:0px;
+      padding:0px;
+      left:0;
+      position:relative;
+      }
+       .MiniSquare1, .MiniSquare2, .MiniSquare3, .MiniSquare4 {
+      border:0px;
+      height:8px;
+      width:8px;
+      margin:0px;
+      padding:0px;
+      }
+       .AStatBar1 { background-color:#".$this->config['AStat_BarColor_Pages']."; top:5px;  }
+       .AStatBar2 { background-color:#".$this->config['AStat_BarColor_Img']."; top:-3px; }
+       .AStatBar3 { background-color:#".$this->config['AStat_BarColor_IP']."; top:-3px;}
+       .AStatBar4 { background-color:#".$this->config['AStat_BarColor_Cat']."; top:-3px;}
+       .AStatBarX { background-color:transparent; top:-3px; height:1px; }
+       .MiniSquare1 { color:#".$this->config['AStat_BarColor_Pages'].";   }
+       .MiniSquare2 { color:#".$this->config['AStat_BarColor_Img'].";  }
+       .MiniSquare3 { color:#".$this->config['AStat_BarColor_IP']."; }
+       .MiniSquare4 { color:#".$this->config['AStat_BarColor_Cat']."; }
+       .StatTableRow:hover { background-color:#".$this->config['AStat_MouseOverColor']."; }
+       .formtable, .formtable P { text-align:left; display:block; }
+       .formtable tr { vertical-align:top; }
+       .window_thumb {
+      position:absolute;
+      border: none;
+      background: none;
+      left:0;
+      top:0;
+      margin:0px;
+      padding:0px;
+      z-index:100;
+      overflow:hidden;
+      visibility:hidden; }
+        .img_thumb {
+      border: solid 3px #ffffff;
+      background: #000000;
+      margin:0px;
+      padding:0px; }
+        .time_request {
+      font-size:83%;
+      text-align:right; }
+        .invisible { visibility:hidden; display:none; }
+      .littlefont { font-size:90%; }
+      table.littlefont th { padding:3px; }
+      table.littlefont td { padding:0px;padding-left:3px;padding-right:3px; }
+      #iplist { visibility:hidden; position:absolute; width:200px; z-index:1000; }
+      .iipsellistitem { float:right; }
+      #iipsellist { width:100%; font-family:monospace; }
+    ";
+
+    return($text);
+  }
+
+  /* ---------------------------------------------------------------------------
+  Function needed for plugin activation
+  --------------------------------------------------------------------------- */
+
+  /*
+    get 'section' enumeration from HISTORY_TABLE
+  */
+  function get_section_enum($add)
+  {
+    $returned=array('', false);
+    $sql = 'SHOW COLUMNS FROM '.HISTORY_TABLE.' LIKE "section"';
+    $result=pwg_query($sql);
+    if($result)
+    {
+      $row = pwg_db_fetch_assoc($result);
+      $list=substr($row['Type'], 5, strlen($row['Type'])-6);
+      $returned[0]=explode(',', $list);
+      if((strpos($list, "'$add'")===false)&&($add!=''))
+      { array_push($returned[0], "'$add'"); }
+      else
+      { $returned[1]=true; }
+      return($returned);
+    }
+  }
+
+  function alter_history_section_enum($section)
+  {
+    $sections=$this->get_section_enum('deleted_cat');
+    if(!$sections[1])
+    {
+      $enums=implode(',', $sections[0]);
+      $sql="ALTER TABLE ".HISTORY_TABLE."
+          CHANGE `section` `section`
+          ENUM (".$enums.") ;";
+      $result=pwg_query($sql);
+      if(!$result)
+      {
+        return(false);
+      }
+    }
+    return(true);
+  }
+
+
+} // astat_root  class
+
+
+
+?>
Index: /extensions/AStat/astat_version.inc.php
===================================================================
--- /extensions/AStat/astat_version.inc.php	(revision 10263)
+++ /extensions/AStat/astat_version.inc.php	(revision 10264)
@@ -15,5 +15,6 @@
   if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-  define('ASTAT_VERSION',  '2.2.2');
-  define('ASTAT_VERSION2', '02.02.02');
+  define('ASTAT_VERSION',  '2.3.0');
+  define('ASTAT_VERSION2', '02.03.00');
+  define('ASTAT_GPC_NEEDED', '3.5.0');
 ?>
Index: /extensions/AStat/main.inc.php
===================================================================
--- /extensions/AStat/main.inc.php	(revision 10263)
+++ /extensions/AStat/main.inc.php	(revision 10264)
@@ -2,5 +2,5 @@
 /*
 Plugin Name: AStat.2
-Version: 2.2.2
+Version: 2.3.0
 Description: Statistiques avancées / Advanced statistics
 Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=172
@@ -63,4 +63,6 @@
 |         |            |   Stat by categories doesn't work when IP filter is activated
 |         |            |
+| 2.3.0   | 2011/04/10 | * mantis: bug 2146
+|         |            |   . compatibility with piwigo 2.2
 |         |            |
 |         |            |
Index: /extensions/AStat/maintain.inc.php
===================================================================
--- /extensions/AStat/maintain.inc.php	(revision 10263)
+++ /extensions/AStat/maintain.inc.php	(revision 10264)
@@ -17,24 +17,21 @@
 if(!defined('ASTAT_PATH')) define('ASTAT_PATH' , PHPWG_PLUGINS_PATH . ASTAT_DIR . '/');
 
-include_once('astat_version.inc.php');
+include_once('astat_version.inc.php'); // => Don't forget to update this file !!
 
-//ini_set('error_reporting', E_ALL);
-//ini_set('display_errors', true);
 
-global $gpc_installed, $gpcNeeded, $lang; //needed for plugin manager compatibility
+global $gpcInstalled, $lang; //needed for plugin manager compatibility
 
 /* -----------------------------------------------------------------------------
-AStat-2 needs the Grum Plugin Classe
+AStat needs the Grum Plugin Classe
 ----------------------------------------------------------------------------- */
-$gpc_installed=false;
-$gpcNeeded="3.0.0";
+$gpcInstalled=false;
 if(file_exists(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'))
 {
   @include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php');
-  // need GPC release greater or equal than 3.0.0
-  if(CommonPlugin::checkGPCRelease(3,0,0))
+  // need GPC release greater or equal than 3.5.0
+  if(CommonPlugin::checkGPCRelease(ASTAT_GPC_NEEDED))
   {
-    @include_once("astat_aim.class.inc.php");
-    $gpc_installed=true;
+    include_once("astat_install.class.inc.php");
+    $gpcInstalled=true;
   }
 }
@@ -42,6 +39,5 @@
 function gpcMsgError(&$errors)
 {
-  global $gpcNeeded;
-  $msg=sprintf(l10n('To install this plugin, you need to install Grum Plugin Classes %s before'), $gpcNeeded);
+  $msg=sprintf(l10n('To install this plugin, you need to install Grum Plugin Classes %s before'), ASTAT_GPC_NEEDED);
   if(is_array($errors))
   {
@@ -56,17 +52,17 @@
 
 
+
 load_language('plugin.lang', ASTAT_PATH);
+
+
+
 
 function plugin_install($plugin_id, $plugin_version, &$errors)
 {
-  global $prefixeTable, $gpc_installed, $gpcNeeded;
-  if($gpc_installed)
+  global $prefixeTable, $gpcInstalled;
+  if($gpcInstalled)
   {
-    $obj = new AStat_AIM($prefixeTable, __FILE__);
-    $obj->deleteConfig();
-    $obj->initConfig();
-    $obj->my_config['installed']=ASTAT_VERSION2;
-    $obj->saveConfig();
-    GPCCore::register($obj->getPluginName(), ASTAT_VERSION, $gpcNeeded);
+    $obj=new AStat_install($prefixeTable, __FILE__);
+    $result=$obj->install();
   }
   else
@@ -78,17 +74,9 @@
 function plugin_activate($plugin_id, $plugin_version, &$errors)
 {
-  global $prefixeTable, $gpc_installed;
-  if($gpc_installed)
+  global $prefixeTable, $gpcInstalled;
+  if($gpcInstalled)
   {
-    $obj = new AStat_AIM($prefixeTable, __FILE__);
-    $obj->initConfig();
-    $obj->loadConfig();
-    $obj->my_config['installed']=ASTAT_VERSION2;
-    $obj->saveConfig();
-    $obj->alter_history_section_enum('deleted_cat');
-  }
-  else
-  {
-    gpcMsgError($errors);
+    $obj=new AStat_install($prefixeTable, __FILE__);
+    $result=$obj->activate();
   }
 }
@@ -96,14 +84,20 @@
 function plugin_deactivate($plugin_id)
 {
+  global $prefixeTable, $gpcInstalled;
+
+  if($gpcInstalled)
+  {
+    $obj=new AStat_install($prefixeTable, __FILE__);
+    $obj->deactivate();
+  }
 }
 
 function plugin_uninstall($plugin_id)
 {
-  global $prefixeTable, $gpc_installed;
-  if($gpc_installed)
+  global $prefixeTable, $gpcInstalled;
+  if($gpcInstalled)
   {
-    $obj = new AStat_AIM($prefixeTable, __FILE__);
-    $obj->deleteConfig();
-    GPCCore::unregister($obj->getPluginName());
+    $obj=new AStat_install($prefixeTable, __FILE__);
+    $result=$obj->uninstall();
   }
   else
@@ -115,3 +109,5 @@
 
 
+
+
 ?>
