###########################################

ALTER TABLE php_stats_cache ADD COLUMN tld varchar(7) NOT NULL default 'unknown' AFTER host;
ALTER TABLE php_stats_cache ADD COLUMN notbrowser tinyint(1) NOT NULL DEFAULT 0 AFTER giorno;
ALTER TABLE php_stats_cache CHANGE COLUMN data data int(11) unsigned NOT NULL DEFAULT 0;

ALTER TABLE php_stats_clicks CHANGE COLUMN creazione creazione int(11) unsigned NOT NULL DEFAULT 0;

CREATE TABLE php_stats_systems_back (os varchar(20) NOT NULL default '',bw varchar(20) NOT NULL default '',reso varchar(10) NOT NULL default '',colo varchar(10) NOT NULL default '',hits int(11) NOT NULL default '0',visits int(11) NOT NULL default '0',mese varchar(8) NOT NULL default '',UNIQUE KEY (os,bw,reso,colo,mese)) TYPE=MyISAM;
INSERT IGNORE INTO php_stats_systems_back SELECT * FROM php_stats_systems;
TRUNCATE TABLE php_stats_systems;
INSERT INTO php_stats_systems SELECT * FROM php_stats_systems_back;
ALTER TABLE php_stats_systems ADD UNIQUE (os,bw,reso,colo,mese);
DROP TABLE php_stats_systems_back;

CREATE TABLE php_stats_langs_back (lang varchar(8) NOT NULL default '',hits int(11) unsigned NOT NULL default '0',visits int(11) unsigned NOT NULL default '0',UNIQUE KEY lang (lang)) TYPE=MyISAM;
INSERT IGNORE INTO php_stats_langs_back SELECT * FROM php_stats_langs;
TRUNCATE TABLE php_stats_langs;
INSERT INTO php_stats_langs SELECT * FROM php_stats_langs_back;
ALTER TABLE php_stats_langs ADD UNIQUE (lang);
DROP TABLE php_stats_langs_back;

CREATE TABLE php_stats_pages_back (data varchar(255) NOT NULL default '0',hits int(11) unsigned NOT NULL default '0',visits int(11) unsigned NOT NULL default '0',no_count_hits int(11) unsigned NOT NULL default '0',no_count_visits int(11) unsigned NOT NULL default '0',presence bigint(20) unsigned default '0', tocount int(10) unsigned NOT NULL default '0', date int(11) unsigned NOT NULL default '0', lev_1 int(10) NOT NULL default '0', lev_2 int(10) NOT NULL default '0', lev_3 int(10) NOT NULL default '0', lev_4 int(10) NOT NULL default '0', lev_5 int(10) NOT NULL default '0', lev_6 int(10) NOT NULL default '0', outs int(10) NOT NULL default '0', titlePage varchar(255) NOT NULL default '',UNIQUE KEY lang (data)) TYPE=MyISAM;
INSERT IGNORE INTO php_stats_pages_back SELECT * FROM php_stats_pages;
TRUNCATE TABLE php_stats_pages;
INSERT INTO php_stats_pages SELECT * FROM php_stats_pages_back;
ALTER TABLE php_stats_pages ADD UNIQUE (data);
DROP TABLE php_stats_pages_back;

ALTER TABLE php_stats_details ADD COLUMN tld varchar(7) NOT NULL DEFAULT 'unknown';
ALTER TABLE php_stats_details CHANGE COLUMN `date` `date` int(11) unsigned NOT NULL DEFAULT 0;
ALTER TABLE php_stats_downloads CHANGE COLUMN creazione creazione int(11) unsigned NOT NULL DEFAULT 0;
ALTER TABLE php_stats_ip CHANGE COLUMN `date` `date` int(11) unsigned NOT NULL DEFAULT 0;
ALTER TABLE php_stats_pages CHANGE COLUMN `date` `date` int(11) unsigned NOT NULL DEFAULT 0;
ALTER TABLE php_stats_query CHANGE COLUMN `date` `date` int(11) unsigned NOT NULL DEFAULT 0;
ALTER TABLE php_stats_referer CHANGE COLUMN `date` `date` int(11) unsigned NOT NULL DEFAULT 0;
DELETE FROM php_stats_daily WHERE data='0000-00-00';

INSERT INTO php_stats_domains VALUES (0, 0, 'ps', 'AS'),(0, 0, 'name', 'UN'),(0, 0, 'nato', 'UN'),(0, 0, 'lan', '');
UPDATE php_stats_domains SET area='AS' WHERE tld='am' || tld='cc' || tld='cx' || tld='az' || tld='ge' || tld='kg' || tld='mv' || tld='kz' || tld='ru' || tld='tj' || tld='tm' || tld='uz';
UPDATE php_stats_domains SET area='EU' WHERE tld='by' || tld='md' || tld='sj' || tld='ua';
UPDATE php_stats_domains SET area='AN' WHERE tld='hn' || tld='tf';
UPDATE php_stats_domains SET area='AM' WHERE tld='gs';
UPDATE php_stats_domains SET area='UN' WHERE tld='edu' || tld='gov' || tld='mil';

# SCRIVO LA NUOVA VERSIONE

UPDATE php_stats_config SET value='0.1.9.2' WHERE name='phpstats_ver';