<?
// AShop-English database initialization

// Open database...

   include "config.inc";
   $db = @mysql_connect("localhost", "$databaseuser", "$databasepasswd");
   @mysql_select_db("$databasename",$db);

$sql = "CREATE TABLE customer (
	firstname varchar(50) not null,
	lastname varchar(50) not null,
	email varchar(50) not null,
	address varchar(50),
	zip varchar(10),
	city varchar(30),
	phone varchar(20),
	customerid int4 not null auto_increment,
	PRIMARY KEY (customerid),
	UNIQUE email (email)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE affiliate (
	user varchar(50) not null,
	password varchar(50) not null,
        firstname varchar(50) not null,
	lastname varchar(50) not null,
        email varchar(50) not null,
        address varchar(50),
        zip varchar(10),
        city varchar(30),
        url varchar(50) not null,
        phone varchar(20),
	payed float(6,2),
        affiliateid int not null auto_increment,
        PRIMARY KEY (affiliateid, user),
	UNIQUE email (email)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE user (
	user varchar(50) not null,
	password varchar(50) not null,
	usertype int not null,
	PRIMARY KEY (user)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE orders (
	customerid int not null,
        orderid int not null auto_increment,
	products varchar(100) not null,
	date varchar(30) not null,
	price varchar(15) not null,
	paymentmethod varchar(15) not null,
	ip varchar(15) not null,
	PRIMARY KEY (orderid)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE orderaffiliate (
	affiliateid int not null,
	orderid int not null,
	PRIMARY KEY (orderid)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE affiliatestats (
        clicks int,
	orders int,
	affiliateid int not null,
	PRIMARY KEY (affiliateid)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE category (
	categoryid int auto_increment not null,
	parentcategoryid int not null,
	name varchar(25) not null,
	description varchar(255) not null,
	PRIMARY KEY (categoryid),
	INDEX parentcategoryid (parentcategoryid),
	INDEX name (name)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE product (
	productid int auto_increment not null,
	name varchar(50) not null,
	description varchar(255) not null,
	price float(5,2) not null,
	PRIMARY KEY (productid),
	INDEX namn (name)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE productcategory (
	productid int not null,
	categoryid int not null,
	PRIMARY KEY (productid, categoryid)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE manufacturer (
	manufacturerid int not null,
	company varchar(30),
	firstname varchar(30) not null,
	lastname varchar(30) not null,
	email varchar(50) not null,
	address varchar(50),
	zip varchar(10),
	city varchar(30),
	phone varchar(20),
	PRIMARY KEY (manufacturerid)
)";

   $result = @mysql_query("$sql",$db);

$sql = "CREATE TABLE productmanufacturer (
	productid int not null,
	manufacturerid int not null,
	PRIMARY KEY (productid, manufacturerid)
)";

   $result = @mysql_query("$sql",$db);

$sql = "INSERT INTO affiliate VALUES('test','test','Test','Testman',
'test@test.com','Street','23455','City','http://www.yahoo.com','055-55555',0,1111)";

   $result = @mysql_query("$sql",$db);

$sql = "INSERT INTO affiliatestats (affiliateid, clicks, orders) VALUES (1111,0,0)";

   $result = @mysql_query("$sql",$db);

$sql = "INSERT INTO category (categoryid, parentcategoryid, name, description) VALUES (1,1,'Software','Computer software')";

   $result = @mysql_query("$sql",$db);

$sql = "INSERT INTO category (categoryid, parentcategoryid, name, description) VALUES (2,1,'Graphics','Photo manipulation and drawing')";

   $result = @mysql_query("$sql",$db);

$sql = "INSERT INTO product (productid, name, description, price) 
VALUES (1, 'Aladobe Photonshop', 'A great program for photon editing', 35)";

   $result = @mysql_query("$sql",$db);

$sql = "INSERT INTO productcategory (productid, categoryid) VALUES (1,2)";

   $result = @mysql_query("$sql",$db);

header("Location: index.php");
?>
