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

echo "Please edit me\n.";
// WARNING! THIS WILL ERASE ALL PREVIOUS DATA AND FILL THE TABLES WITH RANDOM DATA.
// The purpose of this script is to let you check how the diagrams will look like without
// having to wait for many hours for new data to appear in the database.
// Remove the next line if you are sure you want to do this.

mysql_connect("localhost:3360", "root");
mysql_select_db("phpmailstats_test");

mysql_query("DROP TABLE smtpstat_tot_local");
mysql_query("DROP TABLE smtpstat_history_local");
mysql_query("DROP TABLE smtpstat_yearly_local");
mysql_query("DROP TABLE smtpstat_monthly_local");
mysql_query("DROP TABLE smtpstat_weekly_local");
mysql_query("DROP TABLE smtpstat_daily_local");

mysql_query("DROP TABLE smtpstat_tot_relay");
mysql_query("DROP TABLE smtpstat_history_relay");
mysql_query("DROP TABLE smtpstat_yearly_relay");
mysql_query("DROP TABLE smtpstat_monthly_relay");
mysql_query("DROP TABLE smtpstat_weekly_relay");
mysql_query("DROP TABLE smtpstat_daily_relay");

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))");

function randomize($max) {
	global $msgsfr_local, $bytes_from_local, $msgsto_local, $bytes_to_local, $msgsrej_local, $msgsfr_relay, $bytes_from_relay, $msgsto_relay, $bytes_to_relay, $msgsrej_relay;
	mt_srand((double)microtime()*1000000);
	$msgsfr_local = mt_rand(0,$max);
	$bytes_from_local = mt_rand(0,$max);
	$msgsto_local = mt_rand(0,$max);
	$bytes_to_local = mt_rand(0,$max);
	$msgsrej_local = mt_rand(0,$max);
	$msgsfr_relay = mt_rand(0,$max);
	$bytes_from_relay = mt_rand(0,$max);
	$msgsto_relay = mt_rand(0,$max);
	$bytes_to_relay = mt_rand(0,$max);
	$msgsrej_relay = mt_rand(0,$max);
}

for ($hour = 0; $hour <= 23; $hour++) {
	randomize(10);
	mysql_query("INSERT INTO smtpstat_daily_local VALUES ($hour, $msgsfr_local, $bytes_from_local, $msgsto_local, $bytes_to_local, $msgsrej_local)");
	mysql_query("INSERT INTO smtpstat_daily_relay VALUES ($hour, $msgsfr_relay, $bytes_from_relay, $msgsto_relay, $bytes_to_relay, $msgsrej_relay)");
}
for ($dayoftheweek = 0; $dayoftheweek <= 6; $dayoftheweek++) {
	randomize(6000);
	mysql_query("INSERT INTO smtpstat_weekly_local VALUES ($dayoftheweek, $msgsfr_local, $bytes_from_local, $msgsto_local, $bytes_to_local, $msgsrej_local)");
	mysql_query("INSERT INTO smtpstat_weekly_relay VALUES ($dayoftheweek, $msgsfr_relay, $bytes_from_relay, $msgsto_relay, $bytes_to_relay, $msgsrej_relay)");
}
for ($dayofthemonth = 1; $dayofthemonth <= 28; $dayofthemonth++) {
	randomize(10000);
	mysql_query("INSERT INTO smtpstat_monthly_local VALUES ($dayofthemonth, $msgsfr_local, $bytes_from_local, $msgsto_local, $bytes_to_local, $msgsrej_local)");
	mysql_query("INSERT INTO smtpstat_monthly_relay VALUES ($dayofthemonth, $msgsfr_relay, $bytes_from_relay, $msgsto_relay, $bytes_to_relay, $msgsrej_relay)");
}
for ($month = 1; $month <= 12; $month++) {
	randomize(50000);
	mysql_query("INSERT INTO smtpstat_yearly_local VALUES ($month, $msgsfr_local, $bytes_from_local, $msgsto_local, $bytes_to_local, $msgsrej_local)");
	mysql_query("INSERT INTO smtpstat_yearly_relay VALUES ($month, $msgsfr_relay, $bytes_from_relay, $msgsto_relay, $bytes_to_relay, $msgsrej_relay)");
}
for ($year = 1982; $year <= 2003; $year++) { // 1982 and 2003 are just examples, replace them with anything you like
	randomize(100000);
	mysql_query("INSERT INTO smtpstat_history_local VALUES ($year, $msgsfr_local, $bytes_from_local, $msgsto_local, $bytes_to_local, $msgsrej_local)");
	mysql_query("INSERT INTO smtpstat_history_relay VALUES ($year, $msgsfr_relay, $bytes_from_relay, $msgsto_relay, $bytes_to_relay, $msgsrej_relay)");
}

	randomize(1000000);
	mysql_query("INSERT INTO smtpstat_tot_local VALUES ($msgsfr_local, $bytes_from_local, $msgsto_local, $bytes_to_local, $msgsrej_local)");
	mysql_query("INSERT INTO smtpstat_tot_relay VALUES ($msgsfr_relay, $bytes_from_relay, $msgsto_relay, $bytes_to_relay, $msgsrej_relay)");

?>
