


-- create paypal hook to send purchasors reciept and other payment info.
-- validate paypal is connected in the admin page when starting service.
-- make every field required for sponsorship form.

-- INSERT INTO auth_test_users (username,name,email,password_hash,json_data) SELECT username,name,email,password_hash,json_data FROM admin_users;
-- adminpassthrough2000! 

CREATE TABLE IF NOT EXISTS subdomains (
	id INT AUTO_INCREMENT PRIMARY KEY,
	SubDomain VARCHAR(255) NULL,
	Active INT DEFAULT 1, 
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);  
CREATE TABLE IF NOT EXISTS subdomain_properties (
	id INT AUTO_INCREMENT PRIMARY KEY,
	SubDomain VARCHAR(255) NULL,
	PropertyName VARCHAR(255) NULL, 
	PropertyValue TEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS email_users ( 
	id INT AUTO_INCREMENT PRIMARY KEY, 
	username VARCHAR(255) NULL,
	password VARCHAR(255) NULL,
	domain VARCHAR(255) NULL,
	userid VARCHAR(255) NULL,
	home VARCHAR(255) NULL,
	type INT DEFAULT 1,
	level INT DEFAULT 0,
	category INT DEFAULT 0,
	verified INT DEFAULT 0,
	backupEmail VARCHAR(255) NULL,
	firstname VARCHAR(255) NULL,
	lastname VARCHAR(255) NULL,
	token VARCHAR(255) NULL,
	expiry TIMESTAMP NULL,
	uid VARCHAR(255) NULL,
	gid INT NULL, 
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS email_users_copy (
	id INT AUTO_INCREMENT PRIMARY KEY,
	username VARCHAR(255) NULL,
	password VARCHAR(255) NULL,
	domain VARCHAR(255) NULL,
	userid VARCHAR(255) NULL,
	home VARCHAR(255) NULL,
	type INT DEFAULT 1,
	level INT DEFAULT 0,
	category INT DEFAULT 0,
	verified INT DEFAULT 0,
	backupEmail VARCHAR(255) NULL,
	firstname VARCHAR(255) NULL,
	lastname VARCHAR(255) NULL,
	token VARCHAR(255) NULL,
	expiry TIMESTAMP NULL,
	uid VARCHAR(255) NULL,
	gid INT NULL,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);

CREATE TABLE IF NOT EXISTS admin_users (
	id INT AUTO_INCREMENT PRIMARY KEY,
	username VARCHAR(255) NULL,
	name VARCHAR(255) NULL,
	email VARCHAR(255) NULL,
	password_hash VARCHAR(255) NULL,
	json_data MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP() 
);  
ALTER TABLE admin_users ADD root_user INT DEFAULT 0;

CREATE TABLE IF NOT EXISTS sponsor_users (
	id INT AUTO_INCREMENT PRIMARY KEY,
	username VARCHAR(255) NULL,
	name VARCHAR(255) NULL,
	email VARCHAR(255) NULL,
	password_hash VARCHAR(255) NULL,
	json_data MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
); 
CREATE TABLE IF NOT EXISTS configurations (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	reference_abbr VARCHAR(255) NULL,
	json MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);


CREATE TABLE IF NOT EXISTS auth_check (
	id INT AUTO_INCREMENT PRIMARY KEY,
	auth_key VARCHAR(255) NULL,
	expiry TIMESTAMP,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS auth_test_users (
	id INT AUTO_INCREMENT PRIMARY KEY,
	username VARCHAR(255) NULL,
	name VARCHAR(255) NULL,
	email VARCHAR(255) NULL,
	password_hash VARCHAR(255) NULL,
	json_data MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);

CREATE TABLE IF NOT EXISTS notifications (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);


-- ALTER TABLE plugin_paypal RENAME plugin_payments;

CREATE TABLE IF NOT EXISTS plugin_processors (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_forms (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_sponsorships (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_donations (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_events (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_contactus (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_gallery (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_resource_listing (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_settings (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS plugin_analytics (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	viewed INT DEFAULT 1,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);




-- SELECT id,reference_num FROM plugin_subscribers;
-- SELECT id,title,catalog FROM subscriber_articles;
CREATE TABLE IF NOT EXISTS plugin_subscribers (
	id INT AUTO_INCREMENT PRIMARY KEY,
	category VARCHAR(255) NULL,
	reference_abbr VARCHAR(255) NULL,
	reference_num VARCHAR(255) NULL,
	reference_acct VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS subscriber_articles (
	id INT AUTO_INCREMENT PRIMARY KEY,
	reference_num VARCHAR(255) NULL,
	title VARCHAR(255) NULL,
	catalog VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS subscriptions (
	id INT AUTO_INCREMENT PRIMARY KEY,
	reference_num VARCHAR(255) NULL,
	category VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS subscribers (
	id INT AUTO_INCREMENT PRIMARY KEY,
	reference_num VARCHAR(255) NULL,
	name VARCHAR(255) NULL,
	email VARCHAR(255) NULL,
	subscribed INT DEFAULT 1,
	category VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);




CREATE TABLE IF NOT EXISTS payments (
	id INT AUTO_INCREMENT PRIMARY KEY,
	reference_num VARCHAR(255) NULL,
	mode VARCHAR(255) NULL, 
	is_my_processor INT DEFAULT 0,
	processor VARCHAR(255) NULL,
	processor_nameid VARCHAR(255) NULL,
	plugin_category VARCHAR(255) NULL,
	product_name VARCHAR(255) NULL,
	gross_amount VARCHAR(255) NULL,
	net_amount VARCHAR(255) NULL,
	processor_fee VARCHAR(255) NULL,
	own_fee VARCHAR(255) NULL,
	purchaser_email VARCHAR(255) NULL,
	purchaser_name VARCHAR(255) NULL,
	jsontext MEDIUMTEXT,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);


CREATE TABLE IF NOT EXISTS money_accounts (
	id INT AUTO_INCREMENT PRIMARY KEY,
	amount VARCHAR(255) NULL,
	mode VARCHAR(255) NULL,
	type INT DEFAULT 0,
	date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
INSERT INTO money_accounts (amount,mode,type) VALUES ("0.00","live",1);
INSERT INTO money_accounts (amount,mode,type) VALUES ("0.00","sandbox",1);
INSERT INTO money_accounts (amount,mode,type) VALUES ("0.00","live",0);
INSERT INTO money_accounts (amount,mode,type) VALUES ("0.00","sandbox",0);




