<?php
if (self::$db_alter->fetch_table_info('dbtech_vbshop_itemtype'))
{
	$lite = array(
		'customicon' 	=> array(
			'title' 		=> 'Custom Icon',
			'description' 	=> 'Purchase a custom icon for the postbit.',
		),
	);
	foreach ($lite as $filename => $info)
	{
		self::$db->query_write("
			REPLACE INTO `" . TABLE_PREFIX . "dbtech_vbshop_itemtype`
				(`itemtypeid`, `title`, `description`, `filename`)
			VALUES (
				" . self::$db->sql_prepare($filename) . ",
				" . self::$db->sql_prepare($info['title']) . ",
				" . self::$db->sql_prepare($info['description']) . ",
				'/dbtech/vbshop/items/" . $filename . ".php'
			)
		");
	}
	self::report('Populated Table', 'dbtech_vbshop_itemtype');
}

if (self::$db_alter->fetch_table_info('dbtech_vbshop_purchase'))
{
	self::$db_alter->add_field(array(
		'name'       => 'feedbackstatus',
		'type'       => 'tinyint',
		'length'	 => '1',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::report('Altered Table', 'dbtech_vbshop_purchase');
}

if (self::$db_alter->fetch_table_info('dbtech_vbshop_shop'))
{
	self::$db_alter->add_field(array(
		'name'       => 'averagerating',
		'type'       => 'double',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::$db_alter->add_field(array(
		'name'       => 'positivepercent',
		'type'       => 'double',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::$db_alter->add_field(array(
		'name'       => 'negativepercent',
		'type'       => 'double',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::$db_alter->add_field(array(
		'name'       => 'neutralpercent',
		'type'       => 'double',
		'attributes' => 'unsigned',
		'null'       => false,	// True = NULL, false = NOT NULL
		'default'    => '0'
	));
	self::report('Altered Table', 'dbtech_vbshop_shop');
}

// Add itemtype table
self::$db->query_write("
	CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "dbtech_vbshop_feedback`
	(
		`feedbackid` int(10) unsigned NOT NULL AUTO_INCREMENT,
		`userid` int(10) unsigned NOT NULL DEFAULT '0',
		`purchaseid` int(10) unsigned NOT NULL DEFAULT '0',
		`dateline` int(10) unsigned NOT NULL DEFAULT '0',
		`rating` tinyint(1) unsigned NOT NULL DEFAULT '0',
		`feedback` mediumtext,
		PRIMARY KEY (`feedbackid`)
	) ENGINE=MyISAM
");
self::report('Created Table', 'dbtech_vbshop_feedback');

if (class_exists('VBSHOP_CACHE'))
{
	VBSHOP_CACHE::build('shop');
}