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

CREATE TABLE `mxchange_admins` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `login` VARCHAR(100) NOT NULL DEFAULT '',
  `password` VARCHAR(40) NOT NULL DEFAULT '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

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;

CREATE TABLE `mxchange_config` (
  `config` tinyint(1) NOT NULL DEFAULT 0,
  `pass_len` TINYINT(3) UNSIGNED NOT NULL DEFAULT 5,
  `points_register` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `points_ref` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `least_cats` TINYINT(3) UNSIGNED NOT NULL DEFAULT 5,
  `check_double_email` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `check_double_pass` ENUM('Y','N') NOT NULL DEFAULT 'N',
  `admin_notify` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `url_tlock` BIGINT(20) UNSIGNED NOT NULL DEFAULT '86400',
  `test_text` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `max_tlength` BIGINT(20) UNSIGNED NOT NULL DEFAULT '1000',
  `test_subj` ENUM('Y','N') NOT NULL DEFAULT 'Y',
  `autosend_active` ENUM('Y','N') NOT NULL DEFAULT 'N',
  PRIMARY KEY  (`config`)
) TYPE=MyISAM;

INSERT INTO `mxchange_config` VALUES (0,5,2000,200,5,'Y','N','Y',86400,'Y',1000,'Y','N');

CREATE TABLE `mxchange_guest_menu` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `action` VARCHAR(20) NOT NULL DEFAULT '',
  `what` VARCHAR(20) NOT NULL DEFAULT '',
  `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;

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;

CREATE TABLE `mxchange_member_menu` (
  `id` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `action` VARCHAR(20) NOT NULL DEFAULT '',
  `what` VARCHAR(20) NOT NULL DEFAULT '',
  `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',
  `descr` blob NOT NULL,
  `counter` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

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

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;

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;

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;

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

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;

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;

CREATE TABLE `mxchange_user_data` (
  `userid` BIGINT(22) NOT NULL AUTO_INCREMENT,
  `surname` VARCHAR(255) NOT NULL DEFAULT '',
  `family` VARCHAR(255) NOT NULL DEFAULT '',
  `street_nr` VARCHAR(255) NOT NULL DEFAULT '',
  `country` VARCHAR(4) NOT NULL DEFAULT '',
  `zip` VARCHAR(6) NOT NULL DEFAULT '',
  `city` VARCHAR(255) NOT NULL DEFAULT '',
  `email` VARCHAR(255) NOT NULL DEFAULT '',
  `birth_day` CHAR(2) NOT NULL DEFAULT '01',
  `birth_month` CHAR(2) NOT NULL DEFAULT '01',
  `birth_year` VARCHAR(4) NOT NULL DEFAULT '1970',
  `password` VARCHAR(32) NOT NULL DEFAULT '',
  `max_mails` INT(7) NOT NULL DEFAULT 0,
  `receive_mails` INT(7) NOT NULL DEFAULT 0,
  `refid` BIGINT(22) NOT NULL DEFAULT 0,
  `status` ENUM('UNCONFIRMED','CONFIRMED','LOCKED') NOT NULL DEFAULT 'UNCONFIRMED',
  `user_hash` VARCHAR(32) NOT NULL DEFAULT '',
  `REMOTE_ADDR` VARCHAR(15) NOT NULL DEFAULT '0.0.0.0',
  `last_online` VARCHAR(10) NOT NULL DEFAULT 0,
  `last_module` VARCHAR(20) NOT NULL DEFAULT '',
  `ref_clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `total_logins` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  `gender` ENUM('M','F') NOT NULL DEFAULT 'M',
  `used_points` DOUBLE(22,3) NOT NULL DEFAULT '0.000',
  `emails_sent` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY  (`userid`)
) TYPE=MyISAM;

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` DOUBLE(22,3) NOT NULL DEFAULT '0.000',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;

ALTER TABLE `mxchange_config` ADD `max_send` TINYINT(3) UNSIGNED NOT NULL DEFAULT '100';
ALTER TABLE `mxchange_config` ADD `url_blacklist` ENUM('Y','N') NOT NULL DEFAULT 'Y';
ALTER TABLE `mxchange_config` ADD `auto_purge` TINYINT(3) UNSIGNED NOT NULL DEFAULT '14';
ALTER TABLE `mxchange_config` ADD `auto_purge_active` ENUM('Y','N') NOT NULL DEFAULT 'Y';

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';

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;

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;

ALTER TABLE `mxchange_user_data` ADD `joined` VARCHAR(10) NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_config` ADD `last_update` VARCHAR(10) NOT NULL DEFAULT 0;

UPDATE `mxchange_member_menu` SET `locked` = 'N' WHERE 'id'='12' OR 'id'='11' LIMIT 1;

UPDATE `mxchange_guest_menu` SET `counter`=0;
UPDATE `mxchange_member_menu` SET `counter`=0;

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_config` ADD `unconfirmed` BIGINT(20) UNSIGNED NOT NULL DEFAULT '100';
ALTER TABLE `mxchange_config` ADD `profile_lock` BIGINT(20) UNSIGNED NOT NULL DEFAULT '86400';
ALTER TABLE `mxchange_user_data` ADD `last_update` VARCHAR(10) NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_refbanner` ADD `clicks` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_config` ADD `online_timeout` BIGINT(20) UNSIGNED NOT NULL DEFAULT '1800';

ALTER TABLE `mxchange_config` ADD `mad_timestamp` VARCHAR(10) NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_config` ADD `mad_count` BIGINT(20) UNSIGNED NOT NULL;
ALTER TABLE `mxchange_config` ADD `profile_update` BIGINT(20) UNSIGNED NOT NULL DEFAULT '15768000';
ALTER TABLE `mxchange_config` ADD `send_prof_update` ENUM('Y','N') NOT NULL DEFAULT 'Y';
ALTER TABLE `mxchange_config` ADD `resend_profile_update` BIGINT(20) UNSIGNED NOT NULL DEFAULT '172800';

ALTER TABLE `mxchange_user_data` ADD `last_profile_sent` VARCHAR(10) NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_user_data` ADD `notified` ENUM('Y','N') NOT NULL DEFAULT 'N';

ALTER TABLE `mxchange_config` ADD `patch_level` VARCHAR(100) NOT NULL DEFAULT '78';
ALTER TABLE `mxchange_config` ADD `patch_ctime` VARCHAR(10) NOT NULL DEFAULT 0;

ALTER TABLE `mxchange_admins` ADD `email` VARCHAR(255) NOT NULL;

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_data` ADD INDEX (`refid`);
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_config` ADD `code_length` TINYINT(3) UNSIGNED NOT NULL DEFAULT 5;
ALTER TABLE `mxchange_config` ADD `guest_stats` ENUM('MEMBERS','MODULES','INACTIVE') NOT NULL DEFAULT 'MEMBERS';
ALTER TABLE `mxchange_config` ADD `ref_payout` TINYINT(3) UNSIGNED NOT NULL DEFAULT 5;
ALTER TABLE `mxchange_user_data` ADD `ref_payout` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_user_points` ADD `locked_points` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0;

CREATE TABLE `mxchange_extensions` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `ext_name` VARCHAR(255) NOT NULL DEFAULT '',
  `ext_lang_file` 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;

CREATE TABLE `mxchange_jackpot` (
  `ok` CHAR(2) NOT NULL DEFAULT 'ok',
  `points` DOUBLE(23,3) NOT NULL DEFAULT '0.000',
  PRIMARY KEY  (`ok`)
) TYPE=MyISAM;

ALTER TABLE `mxchange_config` ADD `activate_xchange` BIGINT(20) UNSIGNED NOT NULL DEFAULT 100;
ALTER TABLE `mxchange_config` ADD `order_multi_page` ENUM('Y','N') NOT NULL DEFAULT 'Y';
ALTER TABLE `mxchange_config` ADD `display_refid` ENUM('Y','N') NOT NULL DEFAULT 'Y';
ALTER TABLE `mxchange_config` ADD `ip_timeout` BIGINT(20) UNSIGNED NOT NULL DEFAULT 86400;
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';
ALTER TABLE `mxchange_user_data` MODIFY `zip` VARCHAR(6) NOT NULL DEFAULT '';
ALTER TABLE `mxchange_admin_menu` MODIFY `action` VARCHAR(255) NOT NULL DEFAULT '';
ALTER TABLE `mxchange_admin_menu` MODIFY `what` VARCHAR(255) NOT NULL DEFAULT '';
ALTER TABLE `mxchange_user_data` MODIFY `last_module` VARCHAR(255) NOT NULL DEFAULT '';
ALTER TABLE `mxchange_config` ADD `allow_direct_pay` ENUM('N', 'Y') NOT NULL DEFAULT 'N';
ALTER TABLE `mxchange_user_data` MODIFY `last_profile_sent` VARCHAR(10)  NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_user_data` MODIFY `last_update` VARCHAR(10)  NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_user_data` MODIFY `joined` VARCHAR(10)  NOT NULL DEFAULT 0;
ALTER TABLE `mxchange_user_data` MODIFY `last_online` VARCHAR(10)  NOT NULL DEFAULT 0;
