#!/usr/local/bin/php
<?php

mysql_connect("localhost:3360", "root");
mysql_create_db("phpmailstats");
mysql_select_db("phpmailstats");

mysql_query("CREATE TABLE smtpstat_tot_local (msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL)");
mysql_query("CREATE TABLE smtpstat_history_local (year smallint(4) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (year))");
mysql_query("CREATE TABLE smtpstat_yearly_local (month tinyint(2) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (month))");
mysql_query("CREATE TABLE smtpstat_monthly_local (day tinyint(2) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (day))");
mysql_query("CREATE TABLE smtpstat_weekly_local (day tinyint(1) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL,  PRIMARY KEY (day))");
mysql_query("CREATE TABLE smtpstat_daily_local (hour tinyint(2) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (hour))");

mysql_query("CREATE TABLE smtpstat_tot_relay (msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL)");
mysql_query("CREATE TABLE smtpstat_history_relay (year smallint(4) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (year))");
mysql_query("CREATE TABLE smtpstat_yearly_relay (month tinyint(2) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (month))");
mysql_query("CREATE TABLE smtpstat_monthly_relay (day tinyint(2) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (day))");
mysql_query("CREATE TABLE smtpstat_weekly_relay (day tinyint(1) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL,  PRIMARY KEY (day))");
mysql_query("CREATE TABLE smtpstat_daily_relay (hour tinyint(2) unsigned DEFAULT '0' NOT NULL, msgsfr bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_from bigint(20) unsigned DEFAULT '0' NOT NULL, msgsto bigint(20) unsigned DEFAULT '0' NOT NULL, bytes_to bigint(20) unsigned DEFAULT '0' NOT NULL, msgsrej bigint(20) unsigned DEFAULT '0' NOT NULL, PRIMARY KEY (hour))");

for ($timme = 0; $timme < date("G"); $timme++) {
	mysql_query("INSERT INTO smtpstat_daily_local VALUES ($timme,0,0,0,0,0)");
	mysql_query("INSERT INTO smtpstat_daily_relay VALUES ($timme,0,0,0,0,0)");
}
for ($veckodag = 0; $veckodag < date("w"); $veckodag++) {
	mysql_query("INSERT INTO smtpstat_weekly_local VALUES ($veckodag,0,0,0,0,0)");
	mysql_query("INSERT INTO smtpstat_weekly_relay VALUES ($veckodag,0,0,0,0,0)");
}
for ($manadsdag = 1; $manadsdag < date("d"); $manadsdag++) {
	mysql_query("INSERT INTO smtpstat_monthly_local VALUES ($manadsdag,0,0,0,0,0)");
	mysql_query("INSERT INTO smtpstat_monthly_relay VALUES ($manadsdag,0,0,0,0,0)");
}
for ($manad = 1; $manad < date("n"); $manad++) {
	mysql_query("INSERT INTO smtpstat_yearly_local VALUES ($manad,0,0,0,0,0)");
	mysql_query("INSERT INTO smtpstat_yearly_relay VALUES ($manad,0,0,0,0,0)");
}
	mysql_query("INSERT INTO smtpstat_tot_local VALUES ($msgsfr_local,0,0,0,0,0)");
	mysql_query("INSERT INTO smtpstat_tot_relay VALUES ($msgsfr_relay,0,0,0,0,0)");

?>
