DROP TABLE IF EXISTS `mxchange_admin_menu`;
CREATE TABLE `mxchange_admin_menu` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `action` VARCHAR(255) NOT NULL DEFAULT '',
  `what` VARCHAR(255) NULL DEFAULT NULL,
  `title` VARCHAR(50) NOT NULL DEFAULT '',
  `sort` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `descr` BLOB NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_cats`;
CREATE TABLE `mxchange_cats` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `cat` VARCHAR(255) NOT NULL DEFAULT '',
  `visible` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `sort` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_guest_menu`;
CREATE TABLE `mxchange_guest_menu` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `action` VARCHAR(255) NOT NULL DEFAULT '',
  `what` VARCHAR(255) NULL DEFAULT NULL,
  `title` VARCHAR(50) NOT NULL DEFAULT '',
  `sort` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `visible` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `locked` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_max_receive`;
CREATE TABLE `mxchange_max_receive` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `value` MEDIUMINT(9) NOT NULL DEFAULT 0,
  `comment` VARCHAR(255) NOT NULL DEFAULT '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_member_menu`;
CREATE TABLE `mxchange_member_menu` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `action` VARCHAR(255) NOT NULL DEFAULT '',
  `what` VARCHAR(255) NULL DEFAULT NULL,
  `title` VARCHAR(50) NOT NULL DEFAULT '',
  `sort` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `visible` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `locked` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_mod_reg`;
CREATE TABLE `mxchange_mod_reg` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `module` VARCHAR(50) NOT NULL DEFAULT '',
  `locked` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `hidden` ENUM('Y','N') NOT NULL DEFAULT 'N',
  `admin_only` ENUM('Y','N') NOT NULL DEFAULT 'N',
  `title` VARCHAR(200) NOT NULL DEFAULT '',
  `mem_only` ENUM('Y','N') NOT NULL DEFAULT 'N',
  `clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

INSERT INTO `mxchange_mod_reg` VALUES (1,'admin','N','N','Y','','N',0);
INSERT INTO `mxchange_mod_reg` VALUES (2,'index','N','N','N','','N',0);
INSERT INTO `mxchange_mod_reg` VALUES (3,'frameset','Y','N','N','','N',0);
INSERT INTO `mxchange_mod_reg` VALUES (4,'login','N','N','N','','Y',0);
INSERT INTO `mxchange_mod_reg` VALUES (6,'frametester','N','Y','N','','N',0);
INSERT INTO `mxchange_mod_reg` VALUES (7,'loader','N','Y','N','','N',0);
INSERT INTO `mxchange_mod_reg` VALUES (8,'order','N','N','N','','N',0);

DROP TABLE IF EXISTS `mxchange_payments`;
CREATE TABLE `mxchange_payments` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `time` INT(7) NOT NULL DEFAULT 0,
  `payment` FLOAT(5,3) UNSIGNED NOT NULL DEFAULT '0.000',
  `mail_title` VARCHAR(255) NOT NULL DEFAULT '',
  `price` FLOAT(5,5) UNSIGNED NOT NULL DEFAULT '0.00000',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_pool`;
CREATE TABLE `mxchange_pool` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `sender` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `subject` VARCHAR(200) NOT NULL DEFAULT '',
  `text` LONGBLOB NOT NULL,
  `receivers` LONGBLOB NOT NULL,
  `payment_id` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
  `data_type` ENUM('TEMP','SEND','NEW','ADMIN') NOT NULL DEFAULT 'TEMP',
  `timestamp` VARCHAR(10) NOT NULL DEFAULT 0,
  `url` TINYTEXT NOT NULL,
  `target_send` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `cat_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_refbanner`;
CREATE TABLE `mxchange_refbanner` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `url` TEXT NOT NULL,
  `alternate` TEXT NOT NULL,
  `visible` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `counter` BIGINT(22) NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_refdepths`;
CREATE TABLE `mxchange_refdepths` (
  `id` TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
  `level` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
  `percents` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

INSERT INTO `mxchange_refdepths` VALUES (1,0,100);
INSERT INTO `mxchange_refdepths` VALUES (2,1,30);
INSERT INTO `mxchange_refdepths` VALUES (3,2,15);
INSERT INTO `mxchange_refdepths` VALUES (4,3,10);
INSERT INTO `mxchange_refdepths` VALUES (5,4,8);
INSERT INTO `mxchange_refdepths` VALUES (6,5,5);

DROP TABLE IF EXISTS `mxchange_refsystem`;
CREATE TABLE `mxchange_refsystem` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `level` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
  `counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_user_cats`;
CREATE TABLE `mxchange_user_cats` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `cat_id` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_user_points`;
CREATE TABLE `mxchange_user_points` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `userid` BIGINT(22) NOT NULL DEFAULT 0,
  `ref_depth` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0,
  `points` FLOAT(22,3) NOT NULL DEFAULT '0.000',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

ALTER TABLE `mxchange_pool` MODIFY `url` TINYTEXT NOT NULL;
ALTER TABLE `mxchange_pool` CHANGE `url` `url` TINYBLOB NOT NULL;
ALTER TABLE `mxchange_pool` MODIFY `data_type` ENUM('TEMP','SEND','NEW','ADMIN','ACTIVE') NOT NULL DEFAULT 'TEMP';

DROP TABLE IF EXISTS `mxchange_user_links`;
CREATE TABLE `mxchange_user_links` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `stats_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `link_type` ENUM('NORMAL') NOT NULL DEFAULT 'NORMAL',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_user_stats`;
CREATE TABLE `mxchange_user_stats` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `cat_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `payment_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `subject` VARCHAR(200) NOT NULL DEFAULT '',
  `url` TINYBLOB NOT NULL,
  `max_rec` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `timestamp_ordered` VARCHAR(10) NOT NULL DEFAULT '',
  `pool_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `timestamp_sstart` VARCHAR(10) NOT NULL DEFAULT '',
  `timestamp_send` VARCHAR(10) NOT NULL DEFAULT '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

INSERT INTO `mxchange_mod_reg` VALUES (NULL,'chk_login','N','N','N','','N',0);
ALTER TABLE `mxchange_pool` MODIFY `data_type` ENUM('TEMP','SEND','NEW','ADMIN','ACTIVE') NOT NULL DEFAULT 'TEMP';
ALTER TABLE `mxchange_refbanner` ADD `clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0;

DROP TABLE IF EXISTS `mxchange_task_system`;
CREATE TABLE `mxchange_task_system` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `assigned_admin` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `status` ENUM('NEW','OPEN','SOLVED','CLOSED','DELETED') NOT NULL DEFAULT 'NEW',
  `task_type` ENUM('FIRST_USER','SUPPORT_MEMBER','SUPPORT_ADMIN','OTHERS','EXTENSION','EXTENSION_UPDATE') NOT NULL DEFAULT 'FIRST_USER',
  `subject` VARCHAR(255) NOT NULL DEFAULT '',
  `text` LONGBLOB NOT NULL,
  `task_created` VARCHAR(10) NOT NULL DEFAULT 0,
  KEY (`assigned_admin`),
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

ALTER TABLE `mxchange_pool` ADD INDEX (`sender`);
ALTER TABLE `mxchange_pool` ADD INDEX (`payment_id`);
ALTER TABLE `mxchange_pool` ADD INDEX (`cat_id`);
ALTER TABLE `mxchange_refsystem` ADD INDEX (`userid`);
ALTER TABLE `mxchange_task_system` ADD INDEX (`assigned_admin`);
ALTER TABLE `mxchange_task_system` ADD INDEX (`userid`);
ALTER TABLE `mxchange_user_cats` ADD INDEX (`userid`);
ALTER TABLE `mxchange_user_cats` ADD INDEX (`cat_id`);
ALTER TABLE `mxchange_user_links` ADD INDEX (`userid`);
ALTER TABLE `mxchange_user_links` ADD INDEX (`stats_id`);
ALTER TABLE `mxchange_user_points` ADD INDEX (`userid`);
ALTER TABLE `mxchange_user_stats` ADD INDEX (`userid`);
ALTER TABLE `mxchange_user_stats` ADD INDEX (`cat_id`);
ALTER TABLE `mxchange_user_stats` ADD INDEX (`payment_id`);
ALTER TABLE `mxchange_user_stats` ADD INDEX (`pool_id`);

ALTER TABLE `mxchange_user_stats` ADD `clicks` BIGINT(20) UNSIGNED NOT NULL;
ALTER TABLE `mxchange_user_points` ADD `locked_points` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0;

DROP TABLE IF EXISTS `mxchange_extensions`;
CREATE TABLE `mxchange_extensions` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `ext_name` VARCHAR(255) NOT NULL DEFAULT '',
  `ext_active` ENUM('Y','N') NOT NULL DEFAULT 'N',
  `ext_version` VARCHAR(255) NOT NULL DEFAULT 'INVALID',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

DROP TABLE IF EXISTS `mxchange_jackpot`;
CREATE TABLE `mxchange_jackpot` (
  `ok` CHAR(2) NOT NULL DEFAULT 'ok',
  `points` FLOAT(20,3) NOT NULL DEFAULT '0.000',
  PRIMARY KEY  (`ok`)
) TYPE=MyISAM;
ALTER TABLE `mxchange_pool` ADD `zip` VARCHAR(6) NOT NULL DEFAULT '';

ALTER TABLE `mxchange_task_system` CHANGE `task_type` `task_type` VARCHAR(255)  NOT NULL DEFAULT 'FIRST_USER';
