<?php

// Add the administrator field
if (self::$db_alter->fetch_table_info('dbtech_vbmail_mail'))
{
	self::$db_alter->add_field(array(
		'name'       => 'unsubscriptions',
		'type'       => 'int',
		'length'     => '10',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::$db_alter->add_field(array(
		'name'       => 'keywords',
		'type'       => 'int',
		'length'     => '10',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::report('Altered Table', 'dbtech_vbmail_mail');
}

if (self::$db_alter->fetch_table_info('dbtech_vbmail_mailinglist'))
{
	self::$db_alter->add_field(array(
		'name'       => 'unsubscriptions',
		'type'       => 'int',
		'length'     => '10',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::$db_alter->add_field(array(
		'name'       => 'lastmailid',
		'type'       => 'int',
		'length'     => '10',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::$db_alter->add_field(array(
		'name'       => 'lastmaildateline',
		'type'       => 'int',
		'length'     => '10',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::report('Altered Table', 'dbtech_vbmail_mailinglist');
}

// Add the administrator field
if (self::$db_alter->fetch_table_info('dbtech_vbmail_template'))
{
	self::$db_alter->add_field(array(
		'name'       => 'keywords',
		'type'       => 'int',
		'length'     => '10',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::report('Altered Table', 'dbtech_vbmail_template');
}

if (self::$db_alter->fetch_table_info('user'))
{
	self::$db->hide_errors();
	self::$db->query_write("ALTER TABLE " . TABLE_PREFIX . "user ADD dbtech_vbmail_defaultkeyword ENUM('0', '1') NOT NULL DEFAULT '1'");
	self::$db->show_errors();
	self::report('Altered Table', 'user');
}


self::$db->query_write("
	CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX  . "dbtech_vbmail_subscriptionkeyword` (
		`userid` int(10) unsigned NOT NULL,
		`mailinglistid` int(10) unsigned NOT NULL,
		`keywordid` int(10) unsigned NOT NULL,
		`subscribed` enum('0','1') NOT NULL DEFAULT '1',
		PRIMARY KEY (`userid`,`mailinglistid`,`keywordid`)
	) ENGINE=MyISAM 
");
self::report('Created Table', 'dbtech_vbmail_subscriptionkeyword');